Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Powershell to pull all Service accounts

Posted on 2016-10-26
1
Medium Priority
?
156 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 2000 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
Let's recap what we learned from yesterday's Skyport Systems webinar.
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.
Suggested Courses

688 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