Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. $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")}
  2. $CertsInStore = Get-ChildItem -Path Cert:LocalMachineMy
  3. $Store = Get-Item -Path Cert:LocalMachineMy
  4. foreach ($ToRemove in $CertsInStore)
  5. {
  6. $Store.Open("ReadWrite")
  7. $Store.Remove($ToRemove)
  8. $Store.Close()
  9. }
  10. $Certificates = Get-ChildItem -Path Cert:LocalMachineMy | ? {$_.Subject -match [System.Net.Dns]::GetHostByName($env:COMPUTERNAME).HostName}
  11. if (-not [string]::IsNullOrEmpty($Certificates))
  12. {
  13. $Result = "Multiple certificates present" | Out-File "C:SCOMcertimport-result.txt"
  14. exit
  15. } else {
  16. Import-Certificate -FilePath "C:SCOMcertcert_XF-S-RDSAP01P.xe.abb.com.crt" -CertStoreLocation Cert:LocalMachineMy
  17. }
  18. $Certificates = Get-ChildItem -Path Cert:LocalMachineMy | ? {$_.Subject -match [System.Net.Dns]::GetHostByName($env:COMPUTERNAME).HostName}
  19. if ([string]::IsNullOrEmpty($Certificates))
  20. {
  21. $Result = "New certificate failed to import." | Out-File "C:SCOMcertimport-result.txt"
  22. } else {
  23. $Result = "New certificate imported in system store." | Out-File "C:SCOMcertimport-result.txt"
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement