SharpeRAD / Cake.Powershell

Powershell addin for Cake
http://cakebuild.net
MIT License
83 stars 36 forks source link

Issue / Question #90

Closed DavidAGullo closed 1 year ago

DavidAGullo commented 2 years ago

Question Wondering if a command like: Get-ADPrincipalGroupMembership username | select name

where the username would be inserted by the program

Just wondering if this is possible? I don't see how to do it in the Documentations I got: Get-ADPrincipalGroupMembership username working just fine

DavidAGullo commented 2 years ago

nvm I think I found it through a different method:

string username = "username"; using (var runspace = RunspaceFactory.CreateRunspace()) { using (var powerShell = PowerShell.Create()) { string script = "Get-ADPrincipalGroupMembership " + username + " | select name"; ` //start powershell script powerShell.Runspace = runspace; powerShell.Runspace.Open(); powerShell.AddScript(script); foreach (PSObject result in powerShell.Invoke()) { Console.WriteLine("{0}", result); } // End foreach.`