Server: WINFS2K8R2
Folder dum: c:\temp
Script code:
CHANGE TO SERVER THAT HAS SHARES TO EXPORT
$fileServer = “WINFS2K8R2”
$date = get-date
$datefile = get-date -uformat ‘%m-%d-%Y-%H%M%S’
$filename = “C:\TEMP”
#Store shares where security cant be found in this hash table
$problemShares = @{}
Function Get-ShareInfo($shares) {
$arrShareInfo = @()
Foreach ($share in $shares) {
trap{continue;}
write-host $share.name
$strWMI = “\” + $fileServer + “\root\cimv2:win32_LogicalShareSecuritySetting.Name='” + $share.name + “'”
$objWMI_ThisShareSec = $null
$objWMI_ThisShareSec = [wmi]$strWMI
#In case the WMI query or ‘GetSecurityDescriptor’ fails, we retry a few times before adding to ‘problem shares’
For($i=0;($i -lt 5) -and ($objWMI_ThisShareSec -eq $null);$i++) {
sleep -milliseconds 200
$objWMI_ThisShareSec = [wmi]$strWMI
}
$objWMI_SD = $null
$objWMI_SD = $objWMI_ThisShareSec.invokeMethod(‘GetSecurityDescriptor’,$null,$null)
For($j=0;($j -lt 5) -and ($objWMI_SD -eq $null);$j++) {
sleep -milliseconds 200
$objWMI_SD = $objWMI_ThisShareSec.invokeMethod(‘GetSecurityDescriptor’,$null,$null)
}
If($objWMI_SD -ne $null) {
$arrShareInfo += $objWMI_SD.Descriptor.DACL | % {
$_ | select @{e={$share.name};n=‘Name’},
@{e={$share.Path};n=‘Path’},
@{e={$share.Description};n=‘Description’},
AccessMask,
AceFlags,
AceType,
@{e={$.trustee.Name};n=‘User’},
@{e={$.trustee.Domain};n=‘Domain’}
}
}
Else {
$ProblemShares.Add($share.name, “failed to find security info”)
}
}
return $arrshareInfo
}
Write-Host “Finding Share Security Information”
get Shares (Type 0 is “Normal” shares) # can filter on path, etc. with where
$shares = gwmi Win32_Share -computername $fileServer -filter “type=0”
get the security info from shares, add the objects to an array
Write-Host " Complete" -ForegroundColor green
Write-Host “Preparing Security Info for Export”
$ShareInfo = Get-ShareInfo($shares)
Write-Host " Complete" -ForegroundColor green
Write-Host “Exporting to CSV”
Export them to CSV
$ShareInfo | select Name,Path,Description,User,Domain,
AccessMask,AceFlags,AceType | export-csv -noType $filename
Write-Host " Complete" -ForegroundColor green
Write-Host “Your file has been saved to $filename”
If ($problemShares.count -ge 1) {
Write-Host “These Shares Failed to Export:”
}
$problemShares
Sorry here is the piece of code. So i would like to update this script so that it can scan multiple servers and record file share. Any assistance on how to proceed on this?