C# Run VB Script file remotely thriugh PowerShell Invoke Command

  • Thread starter Thread starter Parveen Singla
  • Start date Start date
P

Parveen Singla

Guest
I have a requirement where need to run vbscript remotely through PowerShell Invoke command. I can run the VB Script locally but not remotely as the vbscript file is not present on the remote machine. I dont want to copy the script file on remote machine. Please let me know how to run vb script on remote machine. Below is the code.

Collection<PSObject> output = null;
using (Runspace runSpace = RunspaceFactory.CreateRunspace())
{
runSpace.Open();
using (Pipeline pipeline = runSpace.CreatePipeline())
{
RunspaceInvoke invoke = new RunspaceInvoke();
PowerShell ps = PowerShell.Create();
ps.Runspace = runSpace;
ps.AddCommand("invoke-command");
ps.AddParameter("ComputerName", "RemoteServerName");
ScriptBlock sb = ScriptBlock.Create("cscript E:\\Test\\DeleteFiles.vbs");
ps.AddParameter("ScriptBlock", sb);
output = ps.Invoke();
}
}


Regards, Parveen

Continue reading...
 
Back
Top