• Windows 2012 Core Survival Guide – Managing Services

    Learn about my 2012 Core Survival Guide here.

    Managing Services

    This module is going to look at how to manage services.  The key to using PowerShell to manage any service is to know the exact spelling of the service name.

    How to list services

    PowerShell Command:

    Get-service | Format-table -autosize

    The output below show each services status, name and display name.

     

    How to view a single service

    You can use the "NAME" of the service to display a single service's information.

    PowerShell Command:

    Get-service | where name -eq BITS |Format-list

    In the output below we use the format-list (or fl) to show all of the service's attributes.

     

    How to start a single service

    To start a service there is a simple PowerShell cmdlet called Start-Service. 
    Below I use it to start the BITS service.

    PowerShell Command:

    Start-Service -name BITS

    The output below shows the current status of the service, followed by the command to start the service (in yellow), and followed by a command to confirm the status.

     

    How to stop a service

    Stopping a service is easy too.  I use the Stop-Service cmdlet below to stop the BITS services.

    PowerShell Command:

    Stop-Services -name BITS

    The output below shows the current status of the service, followed by the command to stop the service, and followed by a command to confirm the status.

     

    How view a Service Startup Type

    In order to view the startup type I had to make a WMI call.

    PowerShell Command:

    Get-wmiobject win32_service | where Name -eq WinRM

    In the screen shot below "StartMode" is the startup type of the service and it is set to disabled.  There are 3 possible values for this setting Manual, Automatic, and Disabled.

     

    How to change the Service Startup Type

    The Set-Service cmdlet has three possible settings for "-StartupType" flag: Automatic, Disabled, and Manual.

    PowerShell Command:

    Set-Service -name WinRM -StartupType Automatic

    The output below shows the current status, followed by the command to disable the WinRM service, and followed by the command to confirm the change.

     

    I hope you found this useful.  Please leave me a comment.  Let me know if there are any core tasks you would like me to cover.

    Bruce

     

  • Windows 2012 Core Survival Guide – User Functions

    Learn about my 2012 Core Survival Guide here.

    This blog is going to cover some user functions like logging off, shutting down the OS, and launching Task Manager without the GUI.

    How to log off

    The Logoff command is not a native PowerShell cmdlet but it works from PowerShell.

    Command:

    Logoff

    The screen shot below shows the user logging off their current session.

     

    How to restart server

    To restart the computer you can use the PowerShell cmdlet Restart-computer.  The computer will shut down and restart using this cmdlet.

    PowerShell Command:

    Restart-computer

    The command below will immediately restart the computer.

     

    How to shutdown server

    You can power off the computer using the PowerShell cmdlet Stop-Computer.

    PowerShell Command:

    Stop-computer

    The command below will immediately shutdown and power off the computer.

     

     How to bring up Task Manager

    Windows Server 2012 core includes Task Manager.  At any time you can simply type Ctrl-Shift-ESC to start the task manager.  There is also a command line, and way to launch it from within PowerShell

    Command Line:

    Taskmgr.exe

    PowerShell

    Start-Process Taskmgr

    The output below shows the PowerShell method for starting Task Manager.

     

    I hope you found this useful.  Please leave me a comment.  Let me know if there are any core tasks you would like me to cover.

    Bruce

     

     

     

  • Windows 2012 Core Survival Guide – Event Logs

     Learn about my 2012 Core Survival Guide here.

    This blog looks at how to manage event logs.  The key to using PowerShell to manage any event log is to know the exact spelling of the event log you wish to manager.

    How to view a list of event logs

    To get a list of the event logs I will use the Get-Eventlog cmdlet.  This is one of those cmdlet where piping it to formant-list does not really change the output.   So I left it off.

    PowerShell Command:

    Get-Eventlog -list

    The output below displays a list of event logs active on this computer.

     

    How to view events in an event log

    Because event logs hold many events, it does not make sense to simply list all the event in the log.  Below are several different ways to view parts of the event log.

    Viewing events for the last hour

    PowerShell Command:

    Get-eventlog system -after (get-date).addhours(-1)

     

    The output below shows the last hour of events in the System Log.  You can replace "System" for any of the other event logs.  You can also modify the value in ".addhours" to have a larger value like "(-12)" for the last 12 hours.

     

    Viewing events by event type

    This command only shows the error events for the last hour.

    PowerShell Command:

    Get-eventlog system -after (get-date).addhours(-1) | Where entrytype -eq Error

     In the command above you can replace "Error" with "Information" or "Warning"

     

    Viewing events by event source

    This command show you only the events for the source of "NETLOGON"

    PowerShell Command:

    Get-eventlog system -after (get-date).addhours(-1) | Where Source -eq NetLogon

    You can replace "NETLOGON" with the name of any source:  for example "volmgr".

     

    Viewing events by event index

    Once you have narrowed down the event you wish to review, take note of the index number.  You can display all of the details of that event based on the index number.

    PowerShell Command:

    Get-Eventlog System | where index -eq 5630 | format-list *

     

    How to export event log to an CSV file

    It is often easier to review events by viewing them in a tool like notepad.  You can export any event log to a text file.

    PowerShell Command:

    Get-eventlog system | export-csv -path system.csv

    The output below shows that the event log was written to system.csv (opened in Notepad).  Excel will be the better tool for reviewing the data.

     

    How to clear event log

    PowerShell Command:

    Clear-Eventlog "Windows PowerShell" -clear

    In the output below, notice the number of entries for the Windows PowerShell log is 392.  After the Clear-Eventlog cmdlet has been run the number of entries is zero.

     

    I hope you found this useful.  Please leave me a comment.  Let me know if there are any core tasks you would like me to cover.

    Bruce