How to run this script against a list of servers from a text

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
tonyf
Posts: 12
Joined: Mon Aug 30, 2010 11:59 pm

Re: How to run this script against a list of servers from a

Post by tonyf »

OK Thanks

jvierra
Posts: 14475
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: How to run this script against a list of servers from a

Post by jvierra »

Her eis a help. This script gets the share permissions from a list of computers.
PowerShell Code
Double-click the code block to select all.
Param(
    [string[]]$computers=$env:COMPUTERNAME
)
    
Function Get-SharePermissions($ShareName='scripts', $computer='.'){

    if($share=Get-WmiObject win32_LogicalShareSecuritySetting -Filter "name='$ShareName'" -ComputerName $computer){
        $ACLs=$Share.GetSecurityDescriptor().Descriptor.DACL
        foreach($ACL in $ACLS){
            $perm=switch($ACL.AccessMask){
                2032127 {'Full Control'}
                1245631 {'Change'}
                1179817 {'Read'}
                default { "Unknown:$_"}
            }
            New-Object PsCustomObject -Property @{
                        ComputerName=$computer
                        ShareName=$ShareName
                        Trustee=$(if($ACL.Trustee.Domain){$ACL.Trustee.Domain+'\'})+$($ACL.Trustee.Name)
                        Permission=$perm
                        }
        }
    }
}
Put is in fie and call it.

This will get all shares on local computer:
Get-SharePermissions
This will get all computersz in a file
Get-SharePermissions (cat serverss.txt)
Good Luck

Locked