Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I'm working on a way to use Powershell to get a list of scheduled tasks. Through my research, I determined that the only way to get "most" tasks is to use SCHTASKS. This command does allow for XML output which you can push right into a variable:

$tasks = [xml](SCHTASKS /QUERY /XML ONE)

Now, the problem comes up is that the task name is stored as an XML comment. When added to tasks object, all of this data is stored under the "#comment" key. Using normal addressing rules, you would be accessing:


The above doesn't work of course because the number sign is a special character for comments so it ignores it. I can't escape the character with a back tick "`" so I am at a loss of what to do. I'd rather avoid having to do all of this through a csv file since I loose a lot of data when I do that.


share|improve this question
up vote 5 down vote accepted

Try this:

share|improve this answer
That worked perfectly. Sorry for the delay on accepting it. – Doltknuckle Jan 30 '12 at 23:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.