Microsoft Legacy OS
--
Questions
--
Followers
Top Experts
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Simply do a gci for your serverlist
e.g.
(gci serverlist.txt) | foreach-object {Schtasks.exe /query /s $_ /v"}
You can then do whatever you need to with the output.
(gci servers.txt) | foreach-object {Schtasks.exe /query /s $_ /v"}
(gc serverlist) | foreach-object {Schtasks.exe /query /s $_ /v}






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
PS C:\> (get-content servers.txt) | foreach-object {Schtasks.exe /Query /s $_ /V /FO CSV} | ConvertFrom-CSV |Where { $_.TaskName -ne "TaskName"} | Export-CSV c:\test.csv
There are servers on my list that are not available or the credentials I use may not allow the script to access the computer. Can you show me the ways to add error handling to the script?
Here is a good how to on error handling.
http://www.maxtblog.com/2012/07/using-powershell-error-variable/

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
if (!(Test-connection))
{$computer is unavailable}
To handle servers that are not pingable
you can also write
$scoutput = Schtasks.exe /query /s $_ /v -errorvariable myerror
if ($myerror -contains "some value that you find in an error)
{write-host T"his server did not allow me to query scheduled tasks"}
elseif ($myerror -eq $null)
{
#write your output or send to csv as you do above
}
Microsoft Legacy OS
--
Questions
--
Followers
Top Experts
The Microsoft Legacy Operating System topic includes legacy versions of Microsoft operating systems prior to Windows 2000: All versions of MS-DOS and other versions developed for specific manufacturers and Windows 3/3.1, Windows 95 and Windows 98, plus any other Windows-related versions, and Windows Mobile.