Skip to content

Commit

Permalink
Merge pull request #690 from jing8956/patch-1
Browse files Browse the repository at this point in the history
Fall back to the CIM cmdlet when WMIC is deprecated.
  • Loading branch information
webprofusion-chrisc authored Nov 8, 2024
2 parents 478e7c3 + 5e78442 commit 9460e10
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,14 @@
param($result)

# Apply certificate
wmic /namespace:\\root\cimv2\TerminalServices PATH Win32_TSGeneralSetting Set SSLCertificateSHA1Hash="$($result.ManagedItem.CertificateThumbprintHash)"
if (Get-Command wmic -errorAction SilentlyContinue)
{
# Beginning with Windows Server 2025, WMIC is available as a feature on demand.
wmic /namespace:\\root\cimv2\TerminalServices PATH Win32_TSGeneralSetting Set SSLCertificateSHA1Hash="$($result.ManagedItem.CertificateThumbprintHash)"
}
else
{
# For new development, use the CIM cmdlets instead.
$instance = Get-CimInstance -ClassName Win32_TSGeneralSetting -Namespace root/cimv2/TerminalServices
Set-CimInstance -InputObject $instance -Property @{SSLCertificateSHA1Hash=$result.ManagedItem.CertificateThumbprintHash}
}

0 comments on commit 9460e10

Please sign in to comment.