Hello experts,
In the following script the try catch is not producing any output. The $Error[0].Exception.Message shows the last error and the console displays numerous errors but nothing is being written to the Add-Content file. Looks like it should work, but alas it is not. Would appreciate some assistance in removing my blindness
#Parm( ##Create prompts - pending $Foo_Path="\\david\wvus\Advancement" $Out_Path="David_wvus" #[string]$Foo_Path = "\\david\backups" #[string]$OutPath = "David_backups' #[Parameter(Mandatory,HelpMessage = "Foo_Path enter the folder path to be scanned e.g. \\david\backups and the Out_Path variable which identifies the output file e.g. david_backups")] #Build prompts - pending #) $ErrorLog = @() $FolderPath = Get-Childitem -Directory -Path $Foo_Path -Recurse -Force $Report = @() Foreach ($Folder in $FolderPath) { $Acl = Get-Acl -Path $Folder.FullName Try { $acl = Get-ACL -Path $folder.FullName -ErrorAction Continue } Catch { $ErrorLog = "Path Name: {0} - Error {1} -f $folder", $Error[0].Exception.Message Add-Content -Path D:\PowerShell_temp\foo_test_errors.txt -Value $ErrorLog } } Foreach ($Folder in $FolderPath) { $Acl = Get-Acl -Path $Folder.FullName foreach ($Access in $acl.Access) { $Properties = [ordered]@{'FolderName'=$Folder.FullName;'ADGroup or User'=$Access.IdentityReference;'Permissions'=$Access.FileSystemRights;'Inherited'=$Access.IsInherited} $Report += New-Object -TypeName PSObject -Property $Properties } } $Report | Export-Csv -path "D:\powershell_temp\$($Out_Path)_Folder_permissions_get-acl_dir_psobject_get_childitem_add_line_to_variable_foreach_loop_new_object.csv"