Tag Archives: Export

User ACL Permission Script

$Users = Get-Content "C:user1.txt"
 ForEach ($user in $users)
 {
 $newPath = Join-Path "c:testlocation" -childpath $user
 New-Item $newPath -type directory

$nuser = "gandalf" + $user
 $Access=[System.Security.AccessControl.AccessControlType]"Allow"
 $Rights=[System.Security.AccessControl.FileSystemRights]"FullControl"
 $Prop=[System.Security.AccessControl.PropagationFlags]"NoPropagateInherit"
 $Inherit=[System.Security.AccessControl.InheritanceFlags]"ContainerInherit, ObjectInherit"
 $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($nuser,$Rights,$Inherit,$Prop,$Access)
 $acl = Get-Acl $newpath
 $acl.AddAccessRule($accessRule)
 Set-Acl $newpath -AclObject $acl
 }

Export permissions to CSV file

$OutFile = "C:Permissions.csv"
$Header = "Folder Path,IdentityReference,AccessControlType,IsInherited,InheritanceFlags,PropagationFlags"
Del $OutFile
Add-Content -Value $Header -Path $OutFile

$RootPath = "C:Test"

$Folders = dir $RootPath -recurse | where {$_.psiscontainer -eq $true}

foreach ($Folder in $Folders){
$ACLs = get-acl $Folder.fullname | ForEach-Object { $_.Access }
Foreach ($ACL in $ACLs){
$OutInfo = $Folder.Fullname + "," + $ACL.IdentityReference + "," + $ACL.AccessControlType + "," + $ACL.IsInherited + "," + $ACL.InheritanceFlags + "," + $ACL.PropagationFlags
Add-Content -Value $OutInfo -Path $OutFile
}}

XLSX aanmaken in Powershell

$csvs = Get-ChildItem .* -Include *.csv
 $y=$csvs.Count
 Write-Host “Detected the following CSV files: ($y)”
 foreach ($csv in $csvs)
 {
 Write-Host ” “$csv.Name
 }
 $outputfilename = read-host “Please enter the output file name: “
 Write-Host Creating: $outputfilename
 $excelapp = new-object -comobject Excel.Application
 $excelapp.sheetsInNewWorkbook = $csvs.Count
 $xlsx = $excelapp.Workbooks.Add()
 $sheet=1

foreach ($csv in $csvs)
 {
 $row=1
 $column=1
 $worksheet = $xlsx.Worksheets.Item($sheet)
 $worksheet.Name = $csv.Name
 $file = (Get-Content $csv)
 foreach($line in $file)
 {
 $linecontents=$line -split ‘,(?!s*w+”)’
 foreach($cell in $linecontents)
 {
 $worksheet.Cells.Item($row,$column) = $cell
 $column++
 }
 $column=1
 $row++
 }
 $sheet++
 }

$xlsx.SaveAs($outputfilename)
 $excelapp.quit()