nikink Posted March 31, 2022 Posted March 31, 2022 Hi, I'm using Au3 to run a pshell cmdline and I can see the pshell output in the scite console but I can't capture it in a variable. What am I doing wrong? Func PShell($sCmdline) ;Invoke powershell commandline passed to this function ;Return Powershell Output string ; ALSO: REMOTE PSHELL: Invoke-Command -Computer XXXXX -ScriptBlock{CommandToRun} ;set up powershell cmdline Local $sCommands Local $RunThis = "C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -command " & $sCommands LogMe($RunThis) ; Run powershell cmdline Local $iPID = Run(@ComSpec & ' /c ' & $RunThis, "", @SW_HIDE , $stdout_child) Local $sOutput = "" ; Wait until the process has closed using the PID returned by Run. ProcessWaitClose($iPID) ; Capture powershell cmdline outputstream $sOutput = StdoutRead($iPID) If @error Then ; Powershell output stream has ended LogMe("Powershell output stream has ended - Stdoutread(" & $iPID & ": " & @error & ').' & @LF & 'Finished executing: ' & @LF & $RunThis & @LF & 'Note: This does NOT mean the cmdline worked, only that it finished executing.', $bDisplayMsg) EndIf Return $sOutput EndFunc $sOutput is returning "Error: Stoutread(7448: 1)" where 7448 is the PID I think. So yeah, scratching my head and hoping someone can help.
nikink Posted March 31, 2022 Author Posted March 31, 2022 I guess my ultimate goal is actually to detect whether a computer exists in our Active Directory or not. I've tried a powershell commandline because it was fast. My existing method relies on querying AD for all computer objects then searching the array of all objects. So yeah, inefficient. 😐
nikink Posted April 1, 2022 Author Posted April 1, 2022 Thanks! It didn't work for me, but I appreciate the link. I'll respond in that thread.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now