Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 172
  • Last Modified:

Powershell to pull all Service accounts

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
leadtheway
Asked:
leadtheway
1 Solution
 
SubsunCommented:
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

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now