Quick Powershell tip - Remote Windows Management

Something that I do every now and again (almost every day - many times per day) is to connect to the Event Viewer / Computer Management / Services console of a Remote Windows machine for troubleshooting purposes.

Now of course you could do it like this:

Start -> Run -> compmgmt.msc

Right-Click -> Connect to another computer -> <Computer_Name> -> OK

or you could make it even shorter

Start -> Run -> compmgmt.msc /computer:<Computer_Name>

But after spending some time reading about Powershell today, I decided since I have a Powershell prompt open the whole time would it not be easier to do it in Powershell as well? And maybe also do it one command with switches?

The result is the function below:

function manage-server {
    param ()
    	if ($args.count -eq 0)  {
            do {
    	       $compname = Read-Host "Which server would you like to connect to?"
            } until ($compname -ne $null)
        } else {
        $Compname = $args[0]
        if ($args[1] -eq $null) {
            do {
                $task = read-host "Which task would you like to perform? [Manage/Event/Services]"
            } until (($task -match "manage") -OR ($task -match "event") -OR ($task -match "services"))
        } else {
        $task = $args[1]

    switch ($task) {
        Manage   {compmgmt.msc /computer:$compname}
        Event    {eventvwr.msc /computer:$compname}
        Services {services.msc /computer:$compname}

And to make it even shorter you can create an Alias for the command

New-Alias -Name manage -Value manage-server -Description "Quick Remote Manage Server"

3-5. If the Server name is not entered you will be prompted for input.

10-13. If you have not entered which task you would like to perform - you will be prompted.

18-22. A Switch statement on the task variable will perform the correct task.

I am loving Powershell more and more and more!!