Powershell command generating blank output file

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.

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

Query was tested successfully in PS ISE.

Thanks a ton. This worked in Fixlet Debugger, Have run this on prod, awaiting results.