I have a PowerShell script that I can call from another script with this and it works.
D:\SQLBackups\BkUpAllDBwithDate -Instan .\sqlexpress
I now want to call the same script from VS 2017 Win 10 using VB.net. I have tried many iterations of the following to no avail.
I am not well versed in PS so please bear with me.
Dim myProcess As Process = Process.Start("powershell.exe", "-noexit -file D:\BkUpAllDBwithDate.ps1 -Instan .\sqlexpress ")
Is the path correct?
In your examples they differ.
I stared at that for hours and did not catch that. TY
Now I have something else happening but I will try and chase that down.
Is there a way to trap the PowerShell Error?
Thank you for the help.
you could add this to the code that you want to see the output from
Start-Transcript -path c:\test\transcript.txt -append
your code here
Ok, that worked and said that the parameter is empty meaning I think my vb call is not correct so will try to find what is wrong.
Thank you again for the help.
This is the error trapped.
PS>TerminatingError(Get-SqlDatabase): “Cannot validate argument on parameter ‘ServerInstance’. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.”
Get-SqlDatabase : Cannot validate argument on parameter ‘ServerInstance’. The argument is null or empty. Provide an
argument that is not null or empty, and then try the command again.
At D:\SQLBackUps\BkUpAllDBwithDate.ps1:7 char:33
- Get-SqlDatabase -ServerInstance $Instan |
I guess that means either my VB.Net call is wrong or my Parameter statement in PowerShell is not correct. According to every example I can find they are both correct but any help would be appreciated.
Haven’t used VB.Net but maybe as a troubleshooting step, test with something simple.
E.g. run notepad instead of powershell and pass in a path to a textfile.
If that works then it’s most likely something that doesn’t get correctly passed to/from e.g. the argument section.
E.g. test with just the filename and not the arguments.
You could do that by adding default values in your script as an example.
If that works then you know for sure that it’s the parameters that is causing the issue or something related to it.
I guess another step would be to set at breakpoint at that line and examine what it looks like at runtime.
Another option would be to go through an intermediate step and use ProcessStartInfo and see if that changes anything.
You’ve also a lot more options using ProcessStartInfo.
I have tried some of what you mentioned. Particularly the breakpoint but was unable to figure out what happened in the PowerShell script.
I tried setting a breakpoint in the script but could not get it to work.
Because I needed to get the project completed I just created stored procedures and made calls to them. Worked.
I will try some of your other ideas!