Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $ToRemove = Get-ChildItem -Path Cert:LocalMachineMy | ? {($_.Subject -match [System.Net.Dns]::GetHostByName($env:COMPUTERNAME).HostName) -and ($_.EnhancedKeyUsageList -match "Client Authentication") -and ($_.EnhancedKeyUsageList -match "Server Authentication")}
- $CertsInStore = Get-ChildItem -Path Cert:LocalMachineMy
- $Store = Get-Item -Path Cert:LocalMachineMy
- foreach ($ToRemove in $CertsInStore)
- {
- $Store.Open("ReadWrite")
- $Store.Remove($ToRemove)
- $Store.Close()
- }
- $Certificates = Get-ChildItem -Path Cert:LocalMachineMy | ? {$_.Subject -match [System.Net.Dns]::GetHostByName($env:COMPUTERNAME).HostName}
- if (-not [string]::IsNullOrEmpty($Certificates))
- {
- $Result = "Multiple certificates present" | Out-File "C:SCOMcertimport-result.txt"
- exit
- } else {
- Import-Certificate -FilePath "C:SCOMcertcert_XF-S-RDSAP01P.xe.abb.com.crt" -CertStoreLocation Cert:LocalMachineMy
- }
- $Certificates = Get-ChildItem -Path Cert:LocalMachineMy | ? {$_.Subject -match [System.Net.Dns]::GetHostByName($env:COMPUTERNAME).HostName}
- if ([string]::IsNullOrEmpty($Certificates))
- {
- $Result = "New certificate failed to import." | Out-File "C:SCOMcertimport-result.txt"
- } else {
- $Result = "New certificate imported in system store." | Out-File "C:SCOMcertimport-result.txt"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement