Hi to all.
I need a script in Powershell to list all the Shares from a list of servers with a list of users and share permission level.
Something like:
I only need the share name, the user and the user access level.
Thank you for any idea!
4 Spice ups
DoctorDNS
(DoctorDNS)
3
What have you tried so far?
This is the best that I have
$Header = @"
<style>
TABLE {border-width: 1px;border-style: solid;border-color: blue;border-collapse: separate;}
TH {border-width: 1px;padding: 3px;border-style: solid;border-color: lightblue;background-color: #CEE3F6;}
TD {border-width: 1px;padding: 3px;border-style: solid;border-color: lightblue;}
</style>
"@
function Get-ShareACL {
param(
[String]$Name = "%",
[String]$Computer = $Env:ComputerName
)
$server = Get-Content C:\Users\user\Desktop\test.txt
Foreach-Object {
$Shares = @()
Get-WMIObject Win32_Share -Computer $server -Filter "Name LIKE '$Name'" |
ForEach-Object {
$Access = @()
if ($_.Type -eq 0) {
$SD = (Get-WMIObject Win32_LogicalShareSecuritySetting `
-Computer $server `
-Filter "Name='$($_.Name)'").GetSecurityDescriptor().Descriptor
$SD.DACL | ForEach-Object {
$Trustee = $_.Trustee.Name
if ($_.Trustee.Domain -ne $null) {
$Trustee = "$($_.Trustee.Domain)$Trustee"
}
$Access += New-Object Security.AccessControl.FileSystemAccessRule(
$Trustee, $_.AccessMask, $_.AceType)
}
}
$_ | Select-Object Name, Path, Description, Caption,
@{n='Type';e={
switch ($_.Type) {
0 { "Disk Drive" }
1 { "Print Queue" }
2 { "Device" }
2147483648 { "Disk Drive Admin" }
2147483649 { "Print Queue Admin" }
2147483650 { "Device Admin" }
2147483651 { "IPC Admin" }
}
}},
MaximumAllowed, AllowMaximum, Status, InstallDate,
@{n='Access';e={ $Access }}
}
}|
ConvertTo-HTML -Fragment
}
$GGG = Get-ShareACL
ConvertTo-HTML -Head $Header -Title "SERVER STATUS" -Body "$GGG" |
Out-File C:\Users\user\Desktop\html.htm
in the test.txt file i have 4 servers.
Thank you
#JitenSh
I have used this script, but not all the permissions are shown.
Thank you!
Well, with the help of many colaborators, this is it:
$15 = ConvertTo-Html -Body "<H3>Permission for Shares</H3> "
$shares = get-WmiObject -class Win32_Share -computer $server | where {($_.type -eq "2147483648") -or ($_.type -eq "0")} | select Name
$NTFSobject = @()
Foreach ($share in $shares)
{
$path = "\\{0}\{1}" -f $server, $share.Name
#Write-Host $path -ForegroundColor Yellow
$NTFS = Get-NTFSAccess -Path $path
foreach ($NTF in $NTFS) {
$NTFSprop = [ordered]@{'Server'=$server;'FullName'=$NTF.FullName;'Name'=$NTF.Name;'AccessControlType'=$NTF.AccessControlType;'Account'=$NTF.Account;'AccessRights'=$NTF.AccessRights}
$NTFSobject += New-Object PSObject -Property $NTFSprop
}
}
$NTFS_Shares = $NTFSobject | ConvertTo-HTML -Fragment
Thank you all!