250 Hello

Random Musings on Exchange and Virtualization

Windows Service Log On As Inventory

Windows Service Log On As Inventory

  • Comments 2
  • Likes

At a recent engagement a customer wanted to quickly scan through multiple servers to easily determine which services were set to log on as non-standard accounts, i.e. ones like network service, and local service were OK, but which ones were using an Active Directory logon for example?  They also wanted to search specific portions of the AD, so logic was added to start searching a collection of computers from a given OU. 

 

We took the opportunity to quickly knock up a PowerShell script to leverage the Windows 2008 R2 AD cmdlets in combination with WMI to show which services on multiple computers were using specific credentials.  Please find the script attached to this blog post. 

While the Get-Service cmdlet is able to query services on remote machines using the  -ComputerName parameter it is not able to interrogate the Log On As information for a service.  WMI is able to do this, and by using the Get-WMIObject cmdlet it was simple to query for the desired logon information. 

Note that the OU path is set in the script, and unless you work for TailspinToys.com you will have to edit the OU path to reflect the correct structure. 

Script can be downloaded from the blog ,or scroll down to copy from this post.

Cheers,

Rhoderick

Technorati Tags:

 

 

# ==================================================================
#
# Microsoft provides programming examples for illustration only,
# without warranty either expressed or implied, including, but not
# limited to, the implied warranties of merchantability and/or
# fitness for a particular purpose.
#
# This sample assumes that you are familiar with the programming
# language being demonstrated and the tools used to create and debug
# procedures. Microsoft support professionals can help explain the
# functionality of a particular procedure, but they will not modify
# these examples to provide added functionality or construct
# procedures to meet your specific needs. If you have limited
# programming experience, you may want to contact a Microsoft
# Certified Partner or the Microsoft fee-based consulting line at
# (800) 936-5200.
#
# For more information about Microsoft Certified Partners, please
# visit the following Microsoft Web site:
# https://partner.microsoft.com/global/30000104
#
# Author: Rhoderick Milne
#
# -------------------------------------------------------------------
# History
# -------------------------------------------------------------------
# 23-1-2012   v1.0.0.0  initial release
#
# ===================================================================
#
#
####################################################################################################
FUNCTION ProcessServices
{
    # Write-Host  
    # Write-Host  $service.Name   $service.StartName

    switch ($service.StartName)
   {
        "LocalSystem"
        {
            #"The service stars as LocalSystem"
        }

        "NT AUTHORITY\LocalService"
        {
            #"The service stars as Local Service"
        }
        "NT AUTHORITY\NetworkService"
         {
            #"The service stars as Network Service"
         }
       
        default
        {
            #"This is a Service that we want to look at!"
            Write-Host $Computer.Name   $service.Name   $service.StartName
           
        }
   


   }
    #Write-Host
}

####################################################################################################

####################################################################################################
FUNCTION  ProcessHost
{
Write-Host
$Services = Get-WmiObject Win32_Service -Computer $Computer.Name

ForEach ($Service In $Services)
    {
        
        ProcessServices
        
    }
Write-Host
}

#######################################################################################################

 


############################################ MAIN SCRIPT LOGIC ########################################
$Computers  = Get-ADComputer -Filter * -SearchBase "OU=Servers,DC=TailspinToys,DC=com"

ForEach ($Computer In $Computers)
    {
         ProcessHost
    }

############################################## END SCRIPT #############################################

 

Can You Help Us?  -- Yes !

If you would like to have Microsoft Premier Field Engineering (PFE) visit your company and assist with the topic(s) presented in this blog post, then please contact your Microsoft Premier Technical Account Manager (TAM) for more information on scheduling and our varied offerings!

If you are not currently benefiting from Microsoft Premier support and you’d like more information about Premier, please email the appropriate contact below, and tell them you how you got introduced!

US

Canada

For all other areas please use the US contact point.





Comments
  • wow thats a lot of code a 1 liner would probably sufficed,

    -filter "startname like 'tailspintoys%'"

  • Hi Tony - Potentailly that can be compressed though it was also done intentionally this way to demonstrate a couple of items for scripting purposes.  Plus the above also picks up local service accounts, and not just dominname\serviceaccount

    Totally agree that filtering is the way to go for performance.

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment