Windows server Fileshare list

Hello so far I made a powershell script in a post that can record file shares and place them in a txt file from one server. Here is the powershell script: Script List NTFS folders permissions

My question is how would I go about updating the script so that it can scan multiple servers instead of just one? Any help is greatly appreciated.

dabzz
welcome to the forums.

I wouldn’t change the script at all. Since it already is a function you can use a loop for all servers you want to query and use the function inside the loop.

Regardless of that - we do not customize or migrate scripts on request. We can help if you have issues with code you wrote but we will not write it for you.

So I should just add a foreach loop and I should be good to go? Could you give an example of how would I loop through each of the various servers? Thanks in advance

Please read the help completely including the examples to learn how to use the cmdlets.

Ok thanks for that. Also how we can identify all the file shares on a server and the list of users who have access (plus their level of access)

Please don’t get my wrong, but are you familiar with the concept of internet search engines like Goolge or Bing? If the answer is yes you should start to search for the topics you’re interested in and try the things you find.

If you have an issue with a particular piece of code you wrote yourself you’re very welcome to post this snippet here and we will be happy to help you.

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?

That’s a joke, isn’t it? That’s not funny. :face_with_raised_eyebrow:

First of all … that’s not code you wrote. You just copied an almost 8 years old snippet of code from another forum. And you didn’t even format it as code.

Did you read the answers to that question in the Mircosoft forum?

And I already said we do not customize scripts on request.

We expect you to do your own research and try to solve your problem by yourself in the first place.