PowerShell Script to poll a list of computers to find any with open admin$ shares

 

#

#www.sivarajan.com

#

#Ref: http://santhoshsivarajan.blogspot.com/2010/01/check-admin-share-using-poweshell.html

#

$ComputerFile = New-Item -type file -force “c:\scripts\Success_Computers.txt”

$FailedComputerFile = New-Item -type file -force “c:\scripts\Failed_Computers.txt”

#write-host -fore Blue “`t———————————————”

for ( ; ; ) {

Import-CSV c:\scripts\computers.txt | % {

$Computer = $_.ComputerName

$adminpath = Test-Path \\$Computer\admin$

If ($adminpath -eq “TRUE”){

write-host -fore Green “`tAdmin$ Success`t`t” $Computer “`t”

Add-Content $ComputerFile $Computer

}

#else{

# write-host -fore Red “`tAdmin$ Failed`t`t” $Computer “`t”

# Add-Content $FailedComputerFile $Computer}

# write-host -fore Blue “`t———————————————“

}

Start-Sleep -s 300

}

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s