Why does Powershell say that my variables are empty or null?

Occasional Contributor

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





1 Reply
best response confirmed by __Martin__ (Occasional Contributor)

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: