Solved

Powershell to pull all Service accounts

Posted on 2016-10-26
1
33 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
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 to another domain controller. Log onto the new domain controller with a user account t…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now