Help: Run PowerShell Command in API

Help: Run PowerShell Command in API

ngdnam88
Advocate Advocate
405 Views
2 Replies
Message 1 of 3

Help: Run PowerShell Command in API

ngdnam88
Advocate
Advocate

Dears,

I have this PowerShell command. Please help me how to input to VS.

(Get-Content "D:\Settings.ini") | ForEach-Object { $_ -replace 'OPENAFTEREXPORT=false','OPENAFTEREXPORT=true' } | Set-Content "C:\Settings.ini"

 I'm trying with this way:

Put above command line to .ps1 file then open it with these code:

Script = "R:\Testing.ps1"
Shell("PowerShell.exe " & """" & Script & """", vbNormalFocus)
Script = "R:\Testing.ps1"
Process.Start("PowerShell.exe", Script)

Thank you very much!

0 Likes
Accepted solutions (1)
406 Views
2 Replies
Replies (2)
Message 2 of 3

JelteDeJong
Mentor
Mentor
Accepted solution

I converted this code from this site to VB.net maybe it is some help to you:

Dim ps1File = "C:\my script folder\script.ps1"
Dim startInfo As New ProcessStartInfo()
startInfo.FileName = "powershell.exe"
startInfo.Arguments = String.Format("-NoProfile -ExecutionPolicy unrestricted ""{0}""", ps1File)
Process.Start(startInfo)

 I just tested that it starts Powershell. Not sure if it will run your script correctly.

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 3 of 3

ngdnam88
Advocate
Advocate
Great! I got it. Thanks
0 Likes