Actually, I may have replied too soon on it working.  The .ToString() piece is 
working :)

However, now when I run the whole script against a file/print server that has 
755 file shares,  and I try to read the permissions for the shares, some of 
them disappear.

For example - there are 755 file shares on the server.  If I only pull the 
shares (name, path, description) using " gwmi win32_share -computer 
myfileserver" it works right and returns all 755 shares.

Now 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 plain 
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
         }
      }
    }


From: [email protected] [mailto:[email protected]] On 
Behalf Of Tony Patton
Sent: Thursday, March 27, 2014 3:07 PM
To: [email protected]
Subject: Re: [NTSysADM] RE: Powershell Tip using get-ace for a share permission


I'd be interested, it may be something I have visit shortly for one of our 
contracts.

I currently have scripts running daily to export DNS zones and DFS links.  
Shares and perms were next on the list but never got around to it.

Tony
On 27 Mar 2014 18:29, "Kuhlman, Donald" 
<[email protected]<mailto:[email protected]>> 
wrote:
Thanks much MBS and Kevin.

I used the .ToString() and it's running!

If anyone is interested I can share the final bits...

Don

From: [email protected]<mailto:[email protected]> 
[mailto:[email protected]<mailto:[email protected]>] 
On Behalf Of Michael B. Smith
Sent: Tuesday, March 25, 2014 12:10 PM
To: [email protected]<mailto:[email protected]>
Subject: [NTSysADM] RE: Powershell Tip using get-ace for a share permission

You need a .ToString() in there.

$UniqueShare.AccessRights.ToString()

From: [email protected]<mailto:[email protected]> 
[mailto:[email protected]] On Behalf Of Kuhlman, Donald
Sent: Tuesday, March 25, 2014 1:01 PM
To: [email protected]<mailto:[email protected]>
Subject: [NTSysADM] Powershell Tip using get-ace for a share permission

*         Hi folks. Long time no post...I'm on a new gig and re-subscribed 
using the email address from here.
*         I can't find the Powershell info for the IT-Forum groups so I didn't 
post there yet. I've been googling and checking other sources also, but can't 
seem to get this to work with what I've found.
*         Anyway, I'm working on a script to pull a server inventory including 
shares, share permissions, and other entries and any tip on what may work 
better or instead of would be really appreciated.
I'm able to retrieve the share and ace entries, but when I try to write them to 
an excel sheet, they aren't coming over with the human readable value like 
"Read and execute".  I can output the info to the screen.  I've tried to use a 
Switch command like this but it doesn't work -
#       Switch($UniqueShare.AccessRights)
#                {
# 1179817 {$Sheet1.Cells.Item($intRowShare, 7) = "ReadAndExecute"}
#   }
Below is a code snip showing what I'm doing:
$strComputer = read-host "Enter computer name "
$strComputerDelim = "\\" + $strComputer
$sharelist = get-wmiobject win32_share -ComputerName  $strComputer
foreach ($share in $sharelist)
 {
$ShareAceName = $strComputerDelim + "\" + $share.Name
$ShareAceDetails = get-ace -path $ShareAceName
    foreach ($ShareAce in $ShareAceDetails)
        {
        foreach ($UniqueShare in $ShareAce)
            {
#Populate Shares Sheet (This is only a code snippet)
        write-host $UniqueShare.AccessRights
        $Sheet1.Cells.Item($intRowShare, 7) = $UniqueShare.AccessRights
 $Sheet1.Cells.Item($intRowShare, 8) = $ShareAceDetails.AccessControlType

        $intRowShare = $intRowShare + 1
            }
       }
$intRowShare = $intRowShare + 1
}
Results on screen are like this for the Permissions:
ReadAndExecute, Synchronize
FullControl
ReadAndExecute, Synchronize
ReadAndExecute, Synchronize
GenericExecute, GenericRead
ReadAndExecute, Synchronize
Results in the sheet are like this:
Permission
1179817
Thanks,
Don K


Reply via email to