Tuesday, October 29, 2013

Get all stopped services that are set to autostart

Have you ever wanted to check which services were set to run automatically at boot up but are currently stopped?

      

I find myself wanting to know this all to often, this is one of the first things I check when there is an issue with a service that a server is hosting. The below function will help you find out any and all services that have been configured to start automatically but are currently stopped or not running.





Copy\Paste the below code into a PowerShell window.
<#
.CREATED BY:
    Matthew A. Kerfoot
.CREATED ON:
    10\29\2013
.Synopsis
   Finds Services set to start automatically but are stopped
.DESCRIPTION
   This function will find all services that are set to start automatically at startup but are not currently running.
.EXAMPLE
   Get-Stopped -ComputerName localhost | Out-file "$env:USERPROFILE\Desktop\StoppedServices.txt"
#>

function Get-Stopped {

                      [CmdletBinding()]
              Param ( [Parameter(Mandatory=$false,
                      ValueFromPipelineByPropertyName=$true,
                      Position=0)]
                      $Computername )

         Begin { $Obj = Get-WmiObject -Class Win32_Service }

     Process { $Stopped = $Obj | Where-Object { ($_.StartMode -eq "Auto") -and ($_.State -eq "Stopped") } | 
              Select-Object Name, DisplayName, StartMode, State, Description }

 End { $Stopped | Format-Table -AutoSize }

}
Hit Enter a couple times and then type 'Get-Stopped' to get a table of all service that are set to start when windows boots yet are not running.
PS [www.matthewkerfoot.com]> Get-Stopped

Name           DisplayName                     StartMode State   Description
----           -----------                     --------- -----   -----------
gupdate        Google Update Service (gupdate) Auto      Stopped Keeps your Google software up to d
RemoteRegistry Remote Registry                 Auto      Stopped Enables remote users to modify reg
SCardSvr       Smart Card                      Auto      Stopped Manages access to smart cards read
sppsvc         Software Protection             Auto      Stopped Enables the download, installation
wuauserv       Windows Update                  Auto      Stopped Enables the detection, download, a

PS [www.matthewkerfoot.com]>
Now you can restart any service you feel should be running for example to start the Windows Update service just type, 'Get-Service -Name wuauserv | Start-Service -Verbose'.

Saturday, October 26, 2013

Get 10 CPU consuming processes

Here's a little function that finds the top 10 CPU consuming processes with a nice colorful output. Paste the below code into PowerShell.
<#
.CREATED BY:
    Matthew A. Kerfoot
.CREATED ON:
    10\25\2013
.Synopsis
   Gathers Top 10 CPU consuming processes.
.DESCRIPTION
    This function gathers all processes list them by highest CPU consumption and `
    then displays a nice colorfull display of the top 10 processes listed decending.
.EXAMPLE
   Get-TopCpu -computername localhost -color yellow
#>
Function Get-TopCpu {

            [CmdletBinding()]
    param ( [Parameter(ValueFromPipelineByPropertyName=$true,
            Position=0)]
            [string[]]$computername = $env:COMPUTERNAME,
            [string]$color = "Green"
          )

$num = 1
$Total = 10
$Cpu = Get-Process | Sort-Object CPU -Descending 
Hostname
 foreach ($_ in $Cpu) {
      If ($num -gt $Total) { break }
            write-host "$num) " -NoNewline
            write-host $_.Description  -foregroundcolor "$color" -NoNewline
            write-host " - CPU:"$_.CPU
            $num += 1 }

 Get-WmiObject win32_processor | select LoadPercentage  | fl
}
Get-TopCpu

Hit Enter a couple times and then type 'Get-TopCpu'.

Thursday, October 24, 2013

Server Core to full Windows Server

     Have you ever logged onto a server that has Server Core installed? Did you know how to make the changes you logged on the server to make? Well if not here is a simple step-by-step guide on converting a Windows Server Core installation to the full Windows Server with a GUI.

So we begin with just a command prompt...


c:\Users\Administrator>
Then lets open up PowerShell by Typing 'powershell.exe' or just 'powershell' for short.
c:\Users\Administrator>powershell
TIP : 'powershell.exe -RunAs' opens an elavated PowerShell prompt.
c:\Users\Administrator>powershell
Windows PowerShell
Copyright (C) 2012 Microsoft Corporation. All rights reserved.
PS C:\Users\Administrator>
It's time to install "The Shell" first things first, lets find out which features are needed. To do this I usually utilize the 'Get-WindowsFeature' cmdlet with the '-Name' parameter to search the Windows Feature I'm looking for like this 'Get-WindowsFeature -Name *Server-GUI*'.
PS C:\users\Administrator> Install-WindowsFeature Server-Gui-Shell,Server-Gui-Mgmt-Infra -restart
Break time: Go get a coffee this will take a couple minutes to install and then restart.
Welcome to Windows Server full GUI!