Hi folks. First post here. I'm working on an inventory script based that gets a number of items from a given remote server, including the File Shares and their Permissions using wmi calls.
The script creates several worksheets in Excel with one being a "Shares" list that shows the servername, share name, path, desc, and permissions.
I can use gwmi win32_share -computer computername and it returns the shares. This works fine.
However, when I run the script against a file/print server that has 755 file shares, and the script tries to read the permissions for the shares, the "gwmi win32_share" piece works and returns all 755 shares. But when I try to get the permissions and other details from the results, some of them disappear.
In the code that I have, I take the results of the “gwmi win32_share” and start other loops to read each share and get it’s permissions. In the loops some of the shares that list via the “gwmi win32_share” code don’t show up in the sheet. Some are randomly being dropped. So if I get 755 in the gwmi win32_share call, the loops may only provide 720 of the shares with details.
Is anyone aware of a memory or other kind of issue that I’m overlooking that may be causing some to get “lost” from the list when you have a list of items that contains 755 shares or more?
Thanks
Don K
Code snip as it stands now for the share piece is below –
TOP OF CODE:
$StrComputer = Read-Host "Enter Computer Name "
$StrComputerDelim = “\\” + $strComputer
$ShareItems = gwmi Win32_Share -Comp $StrComputer
..
.
.
LOOP TO GET THE SHARE AND WRITE THE DETAILS
#Populate Shares Sheet
Write-host "Populating Share Information for $strComputer" -ForegroundColor Green
foreach ($objItem in $ShareItems)
{
$ShareAceName = $strComputerDelim + "\" + $objItem.Name
$ShareAceDetails = get-ace -path $ShareAceName
foreach ($ShareAce in $ShareAceDetails)
{
foreach ($UniqueShare in $ShareAce)
{
$Sheet7.Cells.Item($intRowShare, 1) = $StrComputer
$Sheet7.Cells.Item($intRowShare, 2) = $objitem.Name
$Sheet7.Cells.Item($intRowShare, 3) = $objItem.Path
$Sheet7.Cells.Item($intRowShare, 4) = $objItem.Description
$Sheet7.Cells.Item($intRowShare, 5) = $UniqueShare.FullName
$Sheet7.Cells.Item($intRowShare, 6) = $UniqueShare.Account.sid
$Sheet7.Cells.Item($intRowShare, 7) = $UniqueShare.Account.AccountName
$Sheet7.Cells.Item($intRowShare, 8) = $UniqueShare.AccessRights.ToString()
$Sheet7.Cells.Item($intRowShare, 9) = $UniqueShare.AccesscontrolType.ToString()
$Sheet7.Cells.Item($intRowShare, 10) = $UniqueShare.InheritanceEnabled
$Sheet7.Cells.Item($intRowShare, 11) = $UniqueShare.InheritanceFlags.ToString()
$Sheet7.Cells.Item($intRowShare, 12) = $UniqueShare.IsInherited
$Sheet7.Cells.Item($intRowShare, 13) = $UniqueShare.PropagationFlags.ToString()
$intRowShare = $intRowShare + 1
}
}
}
Thanks for any advice!
Don K