I had an interesting problem today I was not quite sure how to address.
I am manipulating certificates in the localmachine store on a remote server and would like to use a function from the local session within that remote session.
I am using write-processlog to create a log of the commands as they are executed.
Function write-Processlog
{ param([string]$logstring)
Write-Host $logstring
Add-Content -LiteralPath $certCreationLog $logstring
}
Then I thought I would like to use this function with in my invoke-command block to return the certificates I remove.
Invoke-Command -ComputerName $FQDN -ScriptBlock {
param ($FQDN) $certs = Get-ChildItem cert:/localmachine/my | Where-Object {$_.Subject -notmatch $FQDN}
foreach($cert in $certs){
$store = Get-Item $cert.PSParentPath
$store.Open('ReadWrite')
$store.Remove($cert)
$store.Close()
}
} -ArgumentList $FQDN -ErrorAction Stop
Any help returning $cert that is removed would be helpful.