I wrote this script a good half a year ago, lost it, and then
found it just recently. It’s a very basic check to test "net use"
access to a list of shares. Additionally (you can hash the $acls bits out if
you don’t want it), we read in the corresponding ACLs too, so if we fail to
connect we know what the share ACL was.
$shares = Get-Content SHARES_FILE.TXT
$acls = Get-Content ACLs_FILE.TXT
$i = 0
$shares | foreach {
Write-Host "Testing share
$_" -ForegroundColor Cyan
& net use T: $_
$result = $null
$drives = (Get-PSdrive).Name
$drives | foreach { if($_ -eq "T"){$result
= $true} }
& net use T: /delete
If ($result){
Write-Host "Successfully
connected!" -ForegroundColor Green
} else {
Write-Host "Failed to
connect!" -ForegroundColor Red
Write-Host ("ACL = " +
$acls[$i]) -ForegroundColor Red
}
$i++
}
Comments
Post a Comment