Most required PowerShell commands for .net WebDevs!

Hi All,

Its been a while since I last wrote something on my blog! However, this is better to write something that is damn needed than just to re-iterate those things that are all across the Web.

As the heading of this topic shows today’s topic is something that I had to spend a lot of time almost once a week. This is to manage the IIS information / server information. For some reason I do not find anything that actually helped me while I looked for quick reference, and it kind of looks embarrassing every time to use the same old commands and windows kind of shouting on us “Please update your knowledgebase!!!”

Here are a few very very important commands that you can use to do daily common things in the Windows server.

  • Get-Command -Name *EventLog (<Command><param><value>) : If you are like me, and do not remember the commands even you use it pretty frequently, then this is your best friend.
    • This command shows you all the possible commands relate to the Eventlog.
    • Show-eventlog : shows you the event log, kind of our old eventVwr command.get
  • Get-ChildItem : Gets items in a specified location. To list the folders in drive C,
    • command below: Get-ChildItem c:/
      This will list all the top level folders. To list all files, folders include sub-folders use the –Recurse parameter
  • Get-WindowsOptionalFeature -Online -FeatureName *Type feature name* : This is to turn windows features on or off. This is to enable IIS in your web server for the first time. As we all know this is generally done through UI Path–> Control Panel\Programs\Programs and Features\TurnWindowsFeaturesOn or off => Choose IIS in the checkbox.
    • get-windowsOptionalFeature -Online -FeatureName IIS-Web* : This command is specific to find all the IIS services to enable.
    • enable-windowsOptionalFeature -Online -FeatureName IIS-Webserverrole -all : Enabling 1
    • enable-windowsOptionalFeature -Online -FeatureName IIS-Webserver -all
    • enable-windowsOptionalFeature -Online -FeatureName IIS-WebDAV -all
    • enable-windowsOptionalFeature -Online -FeatureName IIS-WebSockets -all
    • enable-windowsOptionalFeature -Online -FeatureName IIS-WebServerManagementTools -all

      Once the above steps are done that means you have successfully enabled IIS in your server and this is so good! I think if you do this this way you would see a lot of more information related to the IIS processes then you do in UI. Next steps are to play with the IIS now!
    • get-command -name *iis* : Will show you all that you need to do with IIS!
    • get-iisAppPool : Shows the websites in the app pool.
    • $sm = Get-IISServerManager
      $sm.ApplicationPools[“DefaultAppPool”].Recycle() : This is to recycle the app pool.
    • Stop-Process -Name “<ProcessName>” -Force : This is to stop a process when required delicately.
    • Stop-Process -ID <PID> -Force : This is to stop the process in a different way.
    • taskkill /F /PID 1242 : This is kind of the brutal way to ensure a task is closed. Definitely the last choice among all options. But at the time of need this works! If you know what I mean 🙂
    • tasklist | more : This is in-case you are wondering how to get the task details in the server.

This article will be continued to be updated with more links as well as videos.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top