Forum Discussion
__Martin__
Aug 12, 2020Copper Contributor
Why does Powershell say that my variables are empty or null?
Dear Techcommunity
I wanted to ask why my Script keeps on saying that these variables are empty or null. the following variables are affected:
$pcname = 'server01'
$RDdestfile = "C:\Scripts\Cert\Certificate_04.pfx"
$ThumbprintPath = 'RDS:\GatewayServer\SSLCertificate\Thumbprint'
As you can see, these Variables clearly have something in them.
Here is where I want to use them:
$RemoteSession = New-PSSession -ComputerName $pcname -Credential $cred
Invoke-Command -Session $RemoteSession -ScriptBlock {
Import-PfxCertificate -FilePath $RDdestfile -CertStoreLocation $CertLocation
$certificate = Get-PfxCertificate -FilePath $RDdestfile
Import-Module RemoteDesktopServices
Set-Item -Path $ThumbprintPath -Value $certificate.Thumbprint -ErrorAction Stop
}
I hope you can help me
Greetings
Martin
Because you're trying to use them within a remote session. You either need to set them within the remote session or pass them using a script block/the "using" scope modifier: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_remote_variables?view=powershell-7#using-local-variables
Because you're trying to use them within a remote session. You either need to set them within the remote session or pass them using a script block/the "using" scope modifier: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_remote_variables?view=powershell-7#using-local-variables