Solved

Powershell to pull all Service accounts

Posted on 2016-10-26
1
90 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
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 video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

739 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