Solved

Powershell to pull all Service accounts

Posted on 2016-10-26
1
63 Views
Last Modified: 2016-10-26
Wanting to do a company-wide audit of all Servers and any Services that might be using a Ad user account.  I've seen scripts that will do it per server, but is there a way to do it based on maybe a recursive OU?
0
Comment
Question by:leadtheway
1 Comment
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 41860958
Try this..
$Ou = "CN=Europe,CN=Servers,DC=Domain,DC=com"
$Exclude = "LocalSystem|LocalService|NetworkService"
Import-Module ActiveDirectory
Get-ADComputer -Filter * -SearchBase $Ou | %{
    If (Test-Connection $_.Name -Quiet -Count 2){
    Write-Host "Checking $($_.Name)"
        Get-WmiObject win32_service -ComputerName $_.Name | ?{$_.Startname -and $_.Startname -notmatch $exclude} | Select Name,Startname,__SERVER
    }Else{
     Write-Host "Ping failed for $($_.Name)" -B Red
    }
} | Export-Csv C:\Temp\report.csv -nti

Open in new window


You may also try the code from technet gallery, which has better error handling..
https://gallery.technet.microsoft.com/scriptcenter/PowerShell-script-to-find-6fc15ecb
1

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question