sc.exe is a command line tool for manipulating services on windows. E.g. to list all the services on your machine you can type sc query from a command prompt. However, if you do it from powershell, it instead executes Set-Content because sc is an alias for Set-Content. Even & sc will execute the alias.

How do I run sc.exe from a powershell prompt?

  • I ran into the same problem trying to run where to determine the directory of an exe in the system Path. The conflicting alias was where -> Where-Object. – Edward Brey Dec 16 '14 at 23:53

You have two options, you can either use cmd /c sc query or sc.exe query.


You can do what Justin answered or you can create your own alias for the command. it depends if you need to use the command often throughout a session. If you don't, just listen to Justin. If you do, aliasing isn't a bad idea.

Locate the sc.exe executable that you would like to use. (We'll assume it's in the root of your C:\ drive for now.)

Create the PowerShell alias with the following command:

Set-Alias <What you want to use as an alias> <Path to executable or one of the commands Justin proposed>

For example:

Set-Alias sc2 "C:\cs.exe"

These aliases will disappear when you close PowerShell, export them like so:

Export-Alias "C:\Myaliases.txt"

Then import them when you need to use them (disregard all the errors that show, these errors are due to the fact that PowerShell tries to restore all aliases, including those that are built-in. Of course, these already exist so they are ignored.)

Import-Alias "C:\Myaliases.txt"

More documentation on PowerShell aliasing available on MSTN.

  • That's a good point. I edited you answer since sc comes with windows and you can use the systemroot environment variable to locate it. – Justin Dearing Feb 27 '12 at 16:07
  • @JustinDearing I don't see any (pending) edits... And I do get what you mean about the systemroot. However, not everyone who will come here will be looking for sc specific. Therefore, the answer is now applicable to other aliased executables as well. Built-in or not. – Pylsa Feb 27 '12 at 16:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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