Pregled dijeljenih mapa i prava korisnika putem PowerShell skripte

Prikupljanje dijeljenih mapa na Microsoft Windows poslužiteljima putem PS.

Function Get-NtfsRights($name,$path,$comp)
{
$path = [regex]::Escape($path)
$share = “\\$comp\$name”
$wmi = gwmi Win32_LogicalFileSecuritySetting -filter “path=’$path'” -ComputerName $comp
$wmi.GetSecurityDescriptor().Descriptor.DACL | where {$_.AccessMask -as [Security.AccessControl.FileSystemRights]} |select `
@{name=”Principal”;Expression={“{0}\{1}” -f $_.Trustee.Domain,$_.Trustee.name}},
@{name=”Rights”;Expression={[Security.AccessControl.FileSystemRights] $_.AccessMask }},
@{name=”AceFlags”;Expression={[Security.AccessControl.AceFlags] $_.AceFlags }},
@{name=”AceType”;Expression={[Security.AccessControl.AceType] $_.AceType }},
@{name=”ShareName”;Expression={$share}}
}

gc serverlist.txt | foreach {
if ($shares = Get-WmiObject Win32_Share -ComputerName $_ | Where {$_.Path})
{
$shares | Foreach { Write-Progress -Status “Get share information on $($_.__Server)” $_.Name
Get-NtfsRights $_.Name $_.Path $_.__Server}
}
else {“Failed to get share information from {0}.” -f $($_.ToUpper())}
} | ft Principal,Rights,AceFlags,AceType -GroupBy ShareName -Wrap | Out-File result.txt

 

Izvor: http://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/1903cfde-ad34-464e-9419-94d07ed9de88

 

PowerShell ne dozvoljava pokretanje *.ps1 skripti (‘iliti dobivate poruku “get-help about_signing” for more details.)

Ne možete pokrenuti skripte *.ps1 zato što je izvršavanje skripti zabranjeno na serveru i dobivate poruku “Please see “get-help about_signing” for more details.”?

Provjerite trenutni “execution-policy” sa komandom:

PS C:\Windows\System32> Get-ExecutionPolicy
Restricted
PS C:\Windows\System32>

Za promjeniti aktualan “execution-policy” potrebno je pokrenuti komandu:
Napomena: ova komanda zahtjeva administrativne ovlasti mora biti pokrenuta “elevated” (Pokrenite Powershell koriste?i ‘Run as Administrator’)

PS C:\Windows\System32> Set-ExecutionPolicy Unrestricted
PS C:\Windows\System32> Get-ExecutionPolicy
Unrestricted