Tuesday, February 18, 2025
HomePowershellFind out how to execute PowerShell Scripts (*.ps1) on Distant Computer systems...

Find out how to execute PowerShell Scripts (*.ps1) on Distant Computer systems – SID-500.COM


PowerShell

PowerShell scripts may be executed regionally or remotely. On this article I’ll present how scripts may be executed remotely. It’s important whether or not the script is on the supply pc or on the goal pc. Each situations are potential. Let’s dive in.

PowerShell Script is situated on the Distant Pc

If the script is situated on the distant pc, we should use the Scriptblock parameter.

Right here is an instance:

Invoke-Command -ComputerName mb01 -ScriptBlock {C:tempscript.ps1}

This command will name the script script.ps1 which is situated on the Distant-Pc.

PowerShell Script is situated on the Native Pc

If the script is situated on the distant pc, we should use the FilePath parameter.

Invoke-Command -ComputerName mb01 -FilePath 'C:tempScript.ps1' 

This command will name the script script.ps1 which is situated on the Native Pc.

Various: Set up reference to Enter-PS session

If the script is saved on the distant pc we are able to additionally use Enter-PSSession to hook up with the distant pc and at last execute the script.

Right here is an instance:

Enter-PSSession -ComputerName mb01 # subsequent, navigate to the script folder
.script.ps1 # run the script
Exit-PSSession 

Hope this was useful.

Printed by Patrick Gruenauer

Microsoft MVP on PowerShell [2018-2025], IT-Coach, IT-Marketing consultant, MCSE: Cloud Platform and Infrastructure, Cisco Licensed Academy Teacher.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments