I'm trying to automate enabling SQL Server Always on Availability. I'm running PowerShell as administrator. I'm a domain admin and in the local Administrators group through membership in the AAD DC Administrators group. I am able to enable SQL Server Always on, manually, through the SSCM:

PS C:\Windows\system32> Enable-SqlAlwaysOn -Path "SQLSERVER:\Sql\MSSQLSERVER"

WARNING: Could not obtain SQL Server Service information. An attempt to connect to WMI on 'MSSQLSERVER' failed with the following error: The RPC server is unavailable.

I've also tried adding the credential flag with my same login:

-Credential (Get-Credential "aad.domain.com\myUsername")

I've also tried enabling the Windows Defend Firewall: Allow inbound remote administration exception local computer policy.

PS C:\Windows\system32> $PSVersionTable.PSVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      20348  2227

I've also verified that RPC and WMI services are running, and I've enabled the WMI inbound rules in Defender Firewall.

1

There are 1 best solutions below

0
Adam Winter On

In my case, SQL PowerShell threw this error but it had nothing to do with RPC. It was just that the path was wrong.

In PowerShell, the SQLSERVER:\SQL is known as a PowerShell drive, which is a logical representation of a data store in the file system or elsewhere. PowerShell drives provide a consistent way to navigate and interact with different data stores using familiar file system navigation commands.

PS C:\Windows\system32> cd SQLSERVER:\SQL\
PS SQLSERVER:\SQL\> dir

MachineName
-----------
SQLSRV01


PS SQLSERVER:\SQL\> cd SQLSRV01
PS SQLSERVER:\SQL\SQLSRV01> dir

Instance Name
-------------
DEFAULT


PS SQLSERVER:\SQL\SQLSRV01> cd DEFAULT
PS SQLSERVER:\SQL\SQLSRV01\DEFAULT> Enable-SqlAlwaysOn

So, in my case, the path was:

SQLSERVER:\SQL\[server name]\DEFAULT

You might first need to:

Import-Module SQLPS

In the context of SQL Server PowerShell, SQLSERVER:\SQL is a PowerShell drive specifically designed to interact with SQL Server instances. It's analogous to navigating directories in a file system, but instead of navigating directories and files, you're navigating SQL Server instances and databases.

Once you navigate to the appropriate SQL Server instance using this PowerShell drive, you can then execute commands and access properties specific to that instance using PowerShell cmdlets provided by SQL Server PowerShell module.