Write-Host 'This Powershell Script will Get the User Drives File details separalty for each user and invalid file names and export to CSV file'
#Get Users Folder path
#Set OutPut file path
#Get Users from mapped folder
#Get an array of invalid characters
$invalidCharsNoSpace = [RegEx]::Escape(-join $arrInvalidChars)
#Loop the collection of imported user names and their drive location
#Declare the array variable
$invalidFiles = @()
#get user name and drive path from input file
#Drive path will be user name as each folder will have User name as its main folder name
#Get Files info for the user
for($j=0; $j-le $files.Count; $j++)
if($fileSize -gt 2)
if($files[$j].Name -match "[$invalidCharsNoSpace]")
if($invalidFiles -ne $null)
write-host "Script Ended at $(get-date)"
Gives an output
Please help me on this
It would be really useful if you gave the entire error message.
The error message is
This is the out put after I run the above script
Does it not give a line number?
Without the line number as Bob said it wastes a lot of time. Also put your code inside code blocks.
I noticed an issues at the start of your script.
$UsersSharedPath = "S:\Users\*"; $DrivePath = $UsersSharedPath + $userName # Note $DrivePath has an asterisk in it for example S:\Users\*HSIMPSON $files = Get-ChildItem $DrivePath -Recurse -File
Get-ChildItem will run but with the asterisk in there it won't give you back the file names you want.
You must be logged in to reply to this topic.