Get Certificate - multiple computers
howdy
can me figure out how use certificate against multiple remote servers?
#> [cmdletbinding()] param ( [parameter(valuefrompipeline=$true,valuefrompipelinebypropertyname=$true)] [alias('pscomputername','__server','ipaddress')] [string[]]$computername = $env:computername, [parameter()] [system.security.cryptography.x509certificates.storename]$storename = 'my', [parameter()] [system.security.cryptography.x509certificates.storelocation]$storelocation = 'localmachine', [parameter()] [switch]$includearchive, [parameter()] [string]$issuer, [parameter()] [string]$subject, [parameter()] [string]$thumbprint ) begin { $wherelist = new-object system.collections.arraylist if ($psboundparameters.containskey('issuer')) { [void]$wherelist.add('$_.issuer -like $issuer') } if ($psboundparameters.containskey('subject')) { [void]$wherelist.add('$_.subject -like $subject') } if ($psboundparameters.containskey('thumbprint')) { [void]$wherelist.add('$_.thumbprint -like $thumbprint') } if ($wherelist.count -gt 0) { $where = [scriptblock]::create($wherelist -join ' -and ') write-debug "whereblock: $($where)" } } process { foreach ($computer in $computername) { try { write-verbose ("connecting \\{0}\{1}\{2}" -f $computer,$storelocation,$storename) $certstore = new-object system.security.cryptography.x509certificates.x509store -argumentlist "\\$($computer)\$($storename)", $storelocation if ($psboundparameters.containskey('includearchive')) { $flags = [system.security.cryptography.x509certificates.openflags]'readonly','includearchived' } else { $flags = [system.security.cryptography.x509certificates.openflags]'readonly' } $certstore.open($flags) if ($wherelist.count -gt 0) { $certificates = $certstore.certificates | $where } else { $certificates = $certstore.certificates } $certificates | foreach { $days = switch ((new-timespan -end $_.notafter).days) { {$_ -gt 0} {$_} default {'expired'} } $_ | add-member -membertype noteproperty -name expiresin -value $days -passthru | add-member -membertype noteproperty -name computername -value $computer -passthru } } catch { write-warning "$($computer): $_" } } } }
hi pat,
change [string[]]$computername = $env:computername, [string[]]$computername,
you need permission remote machines too. might need @ getting -credential added advanced function.
another issue have found, if piping get-adcomputer, need add select-object in there. get-adcomputer doesn't seem pass properties if have alias setup.
for example:
get-adcomputer -filter * | select-object * | get-certificatesource select-object here: https://powershell.org/forums/topic/help-with-bypropertyname/
thanks, tim. | please remember mark replies answers if help. |
Windows Server > Windows PowerShell
Comments
Post a Comment