فهرست منبع

wrap main function

Tobias Simetsreiter 5 سال پیش
والد
کامیت
0df2b0f41d
1فایلهای تغییر یافته به همراه18 افزوده شده و 9 حذف شده
  1. 18 9
      permissions.ps1

+ 18 - 9
permissions.ps1

@@ -14,19 +14,28 @@ function Read-InputBoxDialog([string]$Message, [string]$WindowTitle, [string]$De
 if ($inputname -eq $null -or $inputname -eq ""){
 	$inputname = Read-InputBoxDialog -Message "Insert UNC path to Scan" -WindowTitle "Enter Path" -DefaultText "C:\Service\tools"
 }
+if ($inputname -eq $null -or $inputname -eq ""){
+    exit
+}
 
 if ($outputname -eq $null -or $outputname -eq ""){
 	$outputname = Read-InputBoxDialog -Message "Output CSV file" -WindowTitle "Enter Path" -DefaultText "C:\Service\dirs.csv"
 }
+if ($outputname -eq $null -or $outputname -eq ""){
+    exit
+}
 
-$FolderPath = Get-ChildItem -Directory -Path $inputname -Recurse -Force
-$Output = @()
-ForEach ($Folder in $FolderPath) {
-    $Acl = Get-Acl -Path $Folder.FullName
-    ForEach ($Access in $Acl.Access) {
-        $Properties = [ordered]@{'Folder Name'=$Folder.FullName;'Group/User'=$Access.IdentityReference;'Permissions'=$Access.FileSystemRights;'Inherited'=$Access.IsInherited}
-        $Output += New-Object -TypeName PSObject -Property $Properties            
+function main {
+    $FolderPath = Get-ChildItem -Directory -Path $inputname -Recurse -Force
+    $Output = @()
+    ForEach ($Folder in $FolderPath) {
+        $Acl = Get-Acl -Path $Folder.FullName
+        ForEach ($Access in $Acl.Access) {
+            $Properties = [ordered]@{'Folder Name'=$Folder.FullName;'Group/User'=$Access.IdentityReference;'Permissions'=$Access.FileSystemRights;'Inherited'=$Access.IsInherited}
+            $Output += New-Object -TypeName PSObject -Property $Properties            
+        }
     }
+    $Output | Export-Csv -Path $outputname
+    $Output | Out-GridView -PassThru
 }
-$Output | Export-Csv -Path $outputname
-$Output | Out-GridView -PassThru
+main