SOLVED

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

Copper 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

 

Greetings

 

Martin

1 Reply
best response confirmed by __Martin__ (Copper Contributor)
Solution

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_vari...

1 best response

Accepted Solutions
best response confirmed by __Martin__ (Copper Contributor)
Solution

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_vari...

View solution in original post