Skip to content

Commit 9460e10

Browse files
Merge pull request #690 from jing8956/patch-1
Fall back to the CIM cmdlet when WMIC is deprecated.
2 parents 478e7c3 + 5e78442 commit 9460e10

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/Certify.Shared.Extensions/Scripts/Common/RDPListenerService.ps1

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,14 @@
77
param($result)
88

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

0 commit comments

Comments
 (0)