Sujay
May 16, 2018, 3:48pm
1
I have been trying to run a Powershell command which redirects the output to a file but below action is generating a blank output file.
waithidden powershell.exe -ExecutionPolicy Bypass -command “get-wmiobject -query “SELECT * FROM Win32_UserAccount where LocalAccount = ‘True’” | where-object {{$_.SID -match ‘-501$’} | Select-Object Name,Disabled > C:\windows\temp\gu.txt”
waithidden powershell -ExecutionPolicy Bypass -command “get-wmiobject -query “SELECT * FROM Win32_UserAccount where LocalAccount = ‘True’” | where-object {{$_.SID -match ‘-501$’} | Select-Object Name,Disabled > C:\windows\temp\gu.txt”
none of above actions are returning any results.
Can someone please help me correct the above?
I would recommend testing that in PowerShell ISE, line by line, then fixlet debugger, to ensure your script does what you want it to and actually does produce results.
Sean
May 16, 2018, 5:10pm
3
Hi Sujay,
I believe the issue is that you need to escape your double quotes. Try this out:
waithidden powershell -executionpolicy bypass get-wmiobject -query \"SELECT * FROM Win32_UserAccount where LocalAccount = 'True'\" | where-object {{$_.SID -match '-501$'} | Select-Object Name,Disabled > C:\Windows\Temp\gu.txt
1 Like
Sujay
May 17, 2018, 4:34am
4
Query was tested successfully in PS ISE.
Sujay
May 17, 2018, 4:35am
5
Thanks a ton. This worked in Fixlet Debugger, Have run this on prod, awaiting results.