If you create your variables outside the scriptblock the scriptblock will not see them. To achieve this you can use the scope modifier “Using”. … like this:
[quote quote=249062]If you create your variables outside the scriptblock the scriptblock will not see them. To achieve this you can use the scope modifier “Using”. …. like this:
$RemoteSession = New-PSSession -ComputerName $pcname -Credential $cred
Invoke-Command -Session $RemoteSession -ScriptBlock {
Import-PfxCertificate -FilePath $USING:RDdestfile -CertStoreLocation $CertLocation
$certificate = Get-PfxCertificate -FilePath $USING:RDdestfile
Import-Module RemoteDesktopServices
Set-Item -Path $USING:ThumbprintPath -Value $certificate.Thumbprint -ErrorAction Stop
} I assume you will have to use the scope modifer for $CertLocation and $certificate as well.
[/quote] Can I somehow mark this question as the Answer?