How does CPM manage Microsoft SQL Service with WMI?

How does CPM manage Microsoft SQL Service with WMI?

91
Created On 11/10/26 10:57 AM - Last Modified 11/10/26 12:55 PM


Objective


How does CPM manage Microsoft SQL Service with WMI?
 


Environment


11.2;11.3;11.4;11.5;11.6;11.7;12.0;12.1;12.2;12.4;12.3;12.5;12.6;13.0 Privileged Access Manager (PAM, self-hosted);Privilege Cloud Central Policy Manager (CPM)

Procedure


In order to manage the password of service account for Microsoft SQL related services, the CPM utilizes the SqlServer Computer Management WMI namespace provided by Microsoft.
 
You can manually tests this functionality outside of the CPM using the code below with PowerShell from the CPM.  When executed the below script will prompt for a username and password.  This is the username and password to use to connect to the target system to perform the password management process.  The account entered here must have the necessary rights to update the password on the target system's service account.
 
Note: Additional warning information is provided if multiple namespaces for ComputerManagement are found for MS SQL server.  After warning, the code below will loop through each namespace until either the service name is found or the script ends.
 

cls

$target = "<address>"          # replace <address> with the address of the target system

$service = "<service>"         # replace <service> with the name of the service to manage IE. MSSQLSERVER, SQLSERVERAGENT,

                               #   SQLBrowser, SQLWriter, MSSQLFDLauncher, MSSQLServerADHelper, msftesql, or MSSQL

$currentpass = "<currentpass>" # replace <currentpass> with the current password for the service account on the target service

$newpass = "<newpass>"         # replace <newpass> with the password to set for the service account on the target service

$cred = Get-Credential

$CMs = @(Get-WmiObject -Query 'SELECT * FROM __namespace WHERE Name LIKE "ComputerManagement%"' -ComputerName $target -Credential $cred -Namespace 'root\Microsoft\SqlServer')

If ($CMs.count -gt 1) {

    Write-Warning "Multiple WMI ComputerManagement Namespaces found for SqlServer: $($CMs.Count)"

}

#Loop through each namespace to query the object.

foreach ($namespace in $CMs) {

        $WMIService = Get-WmiObject -Query "SELECT * from sqlservice where ServiceName = `"$service`"" -ComputerName $target -Credential $cred -Namespace "$($namespace.__NAMESPACE)\$($namespace.Name)"

    If ($WMIService -eq $null) {

        Write-Error "$service not found in $($namespace.__NAMESPACE)\$($namespace.Name)"

    }

    Else {

        Write-Host "$service found in $($namespace.__NAMESPACE)\$($namespace.Name).  Trying to set password."

        Try {

            $result = $WMIService.SetServiceAccountPassword($currentpass,$newpass)

        }

        Catch {

            Throw ($Error[0] | Select-Object -ExpandProperty Exception | Select-Object -ExpandProperty InnerException).tostring()

        }

        

        If ($result.ReturnValue -eq 0) {

            Write-Host -Object "Password Updated Successfully" -ForegroundColor Green

        }

        Else {

            Write-Host -Object "Password NOT Updated" -ForegroundColor Red

        }

        

        break    

    }

}



Additional Information


Details

Q: 
How does CPM manage Microsoft SQL Service with WMI?

A: 
In order to manage the password of service account for Microsoft SQL related services, the CPM utilizes the SqlServer Computer Management WMI namespace provided by Microsoft.

You can manually tests this functionality outside of the CPM using the code below with PowerShell from the CPM.  When executed the below script will prompt for a username and password.  This is the username and password to use to connect to the target system to perform the password management process.  The account entered here must have the necessary rights to update the password on the target system's service account.

Note: Additional warning information is provided if multiple namespaces for ComputerManagement are found for MS SQL server.  After warning, the code below will loop through each namespace until either the service name is found or the script ends.

cls
$target = "<address>"          # replace <address> with the address of the target system
$service = "<service>"         # replace <service> with the name of the service to manage IE. MSSQLSERVER, SQLSERVERAGENT,
                               #   SQLBrowser, SQLWriter, MSSQLFDLauncher, MSSQLServerADHelper, msftesql, or MSSQL
$currentpass = "<currentpass>" # replace <currentpass> with the current password for the service account on the target service
$newpass = "<newpass>"         # replace <newpass> with the password to set for the service account on the target service

$cred = Get-Credential
$CMs = @(Get-WmiObject -Query 'SELECT * FROM __namespace WHERE Name LIKE "ComputerManagement%"' -ComputerName $target -Credential $cred -Namespace 'root\Microsoft\SqlServer')
If ($CMs.count -gt 1) {
    Write-Warning "Multiple WMI ComputerManagement Namespaces found for SqlServer: $($CMs.Count)"
}

#Loop through each namespace to query the object.
foreach ($namespace in $CMs) {
$WMIService = Get-WmiObject -Query "SELECT * from sqlservice where ServiceName = `"$service`"" -ComputerName $target -Credential $cred -Namespace "$($namespace.__NAMESPACE)\$($namespace.Name)"

    If ($WMIService -eq $null) {
        Write-Error "$service not found in $($namespace.__NAMESPACE)\$($namespace.Name)"
    }
    Else {
        Write-Host "$service found in $($namespace.__NAMESPACE)\$($namespace.Name).  Trying to set password."

        Try {
            $result = $WMIService.SetServiceAccountPassword($currentpass,$newpass)
        }
        Catch {
            Throw ($Error[0] | Select-Object -ExpandProperty Exception | Select-Object -ExpandProperty InnerException).tostring()
        }
        
        If ($result.ReturnValue -eq 0) {
            Write-Host -Object "Password Updated Successfully" -ForegroundColor Green
        }
        Else {
            Write-Host -Object "Password NOT Updated" -ForegroundColor Red
        }
        
        break    
    }
}



Actions
  • Print
  • Copy Link

    https://knowledgebase.paloaltonetworks.com/KCSArticleDetail?id=kA1hj0000001ULpCAM&lang=en_US&refURL=http%3A%2F%2Fknowledgebase.paloaltonetworks.com%2FKCSArticleDetail