Yann Cogez
Yann Cogez

Reputation: 1

Execute Powershell script on older version of PS

I'm working on PowerShell 5.0 and i want to start a script on another server running PowerShell 2.0.

I tried to use Invoke-Command but it doesn't work, do you know if there is a solution to "emulate" the script on my PC ?

Invoke-Command -ScriptBlock {Get-printer} -ComputerName server

The term Get-Printer is not recognized as the name of a CmdLet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Upvotes: 0

Views: 305

Answers (2)

Yann Cogez
Yann Cogez

Reputation: 1

Thanks for the answer i know the other way with the -ComputerName, I want to use Invoke-command in priority.

I'll try Get-wmiObject

Upvotes: 0

DarkLite1
DarkLite1

Reputation: 14695

In this case it's easier to use the parameter ComputerName. It will connect to the remote machine and retrieve the printers on its own.

Get-Printer -ComputerName 'Server'

Another option would be to use WMI:

Get-WmiObject -ClassName 'Win32_Printer' -ComputerName 'Server'

And if you really want to use Invoke-Command:

Invoke-Command -ComputerName 'Server' -ScriptBlock {
    Get-WmiObject -ClassName 'Win32_Printer'
}

The last option will execute the code on the remote machine. It will most likely work because the CmdLet Get-WmiObject is present in the older version of PowerShell on the remote machine.

Upvotes: 2

Related Questions