Link to home
Start Free TrialLog in
Avatar of David L. Hansen
David L. HansenFlag for United States of America

asked on

How to use Visual Studio's AddArgument method found in the PowerShell Namespace

Chris Dent helped me get a powershell script running in this threat.. https://www.experts-exchange.com/questions/29012337/How-to-get-a-Powershell-script-to-launch-from-Visual-Studio.html?anchor=a42068798¬ificationFollowed=186554345&anchorAnswerId=42068798#a42068798

Now I'm running that same code but against a server-based script. The only code I can get to work is this, which prevents me from catching all the errors that might be thrown (terminating and non-terminating ones).
startInfo.Arguments = "-ExecutionPolicy UnRestricted -File " & iScriptPath

Open in new window

I'd like to use the AddArgument method (see below) instead (of the code above) to pass my ExecutionPolicy parameter and then invoking the script. Like this:
_Host.AddArgument("-ExecutionPolicy UnRestricted")
_Host.AddScript(iScriptPath)
Dim psResults As Object = _Host.Invoke()

Open in new window

The issue is that "_Host.AddArgument("-ExecutionPolicy UnRestricted") wants Object instead of String and throws an error they way I have it presently.

Btw, Microsoft's site has preciousness little to help on this method.
https://msdn.microsoft.com/en-us/library/system.management.automation.powershell.addargument(v=vs.85).aspx
ASKER CERTIFIED SOLUTION
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of David L. Hansen

ASKER

Worked like a champ! Thanks.