//]]> MICROSOFT LIVE SUPPORT: Powershell: find all services running a domain SA account

Tuesday, May 6, 2014

Powershell: find all services running a domain SA account



Situation:

We are designing a new security model on our domain. For this we needed an overview of all servers running Windows, and to see which services on these servers are started by a domain account.

 What did you do?

undefined
Powershell is the obvious choice here. So I asked our jobstudent and scriptguru to help me out here. Here’s what he came up with:

1 #### Gets all the servers
2
3 $search = New-Object DirectoryServices.DirectorySearcher([ADSI]“”)
4 $search.filter = “(&(objectCategory=computer)(|(operatingSystem=Windows NT)(operatingSystem=Windows Server*)))”
5 $results = $search.Findall()
6 $ServerNames = @()
7 foreach($result in $results){
8
9 $userEntry = $result.GetDirectoryEntry()
10 $os = $userEntry.operatingSystem
11 ##Write-Output($os)
12
13 $ServerNames += $userEntry.name
14 }
15
16 ##### Pings the servers first if succesfull tries to access it ######
17
18 foreach ($Server in $ServerNames) {
19 if (test-Connection -ComputerName $Server -Count 1 -Quiet ) {
20
21 try{
22 Write $Server
23 get-wmiobject win32_service -comp $server -filter "Startname Like '%work-around.it'" -ErrorAction Stop | select name,startname | Format-Table -HideTableHeaders
24 }
25 catch{
26 Write-Output("Access denied to $Server !")
27 }
28
29 }else {
30 Write-Output("$Server seems dead not pinging!")
31 }
32 }
33
34 ########## end of script #######################
In the first part of the script, it queries the AD on all computers running either Windows NT or Windows server *
In the second part, it tries to ping the server to see if it’s still alive (otherwise prints: Server seems dead not pingable) and if so, tries to access it.
Next: it connects to the win32_service and searches for “%work-around.it. If a result is found, it will display it underneath the server.



If the issue is still not fixed, it can be a very critical problem with your computer affecting your personal data and the Windows Operating System. You will have to chat with our Experts or you can check with your local technician to get the problems fixed with very high priority.


                                         undefined

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.

DMCA.com Protection Status