PowerShell in remote scripting

Started by Keith

Keith

PowerShell in remote scripting   12 February 2025, 10:47

Hello. How do I get this to work in remote scripting? I am trying to pull the subfolder from a folder on remote computers.
Const Quote = """"

Dim cmd
cmd = "powershell.exe " "Get-ChildItem -Path "\\computername\C$\Program Files\SentinelOne -directory ""

'Create process object and execute PowerShell
Set proc = Internal.CreateObject("process")
proc.execute(cmd)

'Check process exit code
If proc.ExitCode = 0 Then

'Traverse output lines
For Each line in proc.output
Output.Write Line
Next
Else
Output.Write "Exit code " & proc.ExitCode
End If
SoftPerfect Support forum - Ann avatar image
Ann

Re: PowerShell in remote scripting   12 February 2025, 11:05

It looks like quotation marks were used incorrectly in your script. It is easier to place everything in a single string. Below is a working example. You can replace the path with C:\ for testing.
Dim cmd
cmd = "powershell.exe Get-ChildItem -Path \\computername\C$\Program Files\SentinelOne -directory"

'Create process object and execute PowerShell
Set proc = Internal.CreateObject("process")
proc.execute(cmd)

'Check process exit code
If proc.ExitCode = 0 Then

'Traverse output lines
For Each line in proc.output
Output.Write Line
Next
Else
Output.Write "Exit code " & proc.ExitCode
End If

Reply to this topic

Sometimes you can find a solution faster if you try the forum search, have a look at the knowledge base, or check the software user manual to see if your question has already been answered.

Our forum rules are simple:

  • Be polite.
  • Do not spam.
  • Write in English. If possible, check your spelling and grammar.

Author:

Email:

Subject

A brief and informative title for your message, approximately 4–8 words:

     

Spam prevention: please enter the following code in the input field below.

 **     **  ********    ******   ********  **    ** 
 ***   ***  **     **  **    **  **        ***   ** 
 **** ****  **     **  **        **        ****  ** 
 ** *** **  ********   **        ******    ** ** ** 
 **     **  **         **        **        **  **** 
 **     **  **         **    **  **        **   *** 
 **     **  **          ******   ********  **    ** 

Message: