- 1 year ago
How can I execute a VBScript remotely using PowerShell?
Comment
1 / 1
To execute a VBScript remotely using PowerShell, you can use the Invoke-Command
cmdlet. Here's how you can do it:
- Create a PowerShell script that uses the
Invoke-Command
cmdlet to execute the VBScript on the remote computer. Save this script with a.ps1
extension. For example,RunVbsScript.ps1
:
powershellparam (
[string]$ComputerName,
[string]$ScriptPath
)
$scriptBlock = {
param($ScriptPath)
cscript.exe $ScriptPath
}
Invoke-Command -ComputerName $ComputerName -ScriptBlock $scriptBlock -ArgumentList $ScriptPath
- Now, you can run the PowerShell script from your local machine, passing the remote computer name and the path to the VBScript as arguments:
powershell.\RunVbsScript.ps1 -ComputerName "RemoteComputerName" -ScriptPath "C:\Path\To\Your\Script.vbs"
Replace "RemoteComputerName"
with the name of the remote computer where you want to execute the VBScript, and "C:\Path\To\Your\Script.vbs"
with the actual path to your VBScript on the remote computer.
Note: To execute PowerShell scripts remotely, you might need to enable PowerShell remoting on the remote computer. You can use the Enable-PSRemoting
cmdlet to enable remoting. Additionally, you might need administrative privileges on the remote computer to run the VBScript.