I have a simple script that basically queries an OU in AD, obtains the samaccountnames of those users. And then deletes the contents of the users folder based on their samaccountname, excluding a few folders etc...
SCRIPT
$OUPath = '<domain name>/Student/ClassRoom9'
Get-QAduser -SearchRoot $OUPath -SearchScope OneLevel | Select-Object "samaccountname" | ForEach-Object { $Student = $_.samaccountname $studpath = "d:\script\$Student"
Remove-Item -recurse $studpath\* -exclude Desktop,Documents,Favorites,Music,Pictures,Videos
}
The script runs perfectly OK, and does the job. But when I view the "Run History". I get a "STATUS: FAILED"
And then the error as in the subject "The Expression after '&' in a pipeline element produced an object that was not valid. It must result in a command name, a script block, or a CommandInfo object"
Anyone any ideas?