I’m hoping for any assistance with this script. The script below need to to the following:
- read the folder in the $DRIVEPATH variable and create a list of sub-folder name in a CSV file, which the script does create correctly
- Then use the CSV file to run a command (ForEach ($proj in $projlist) line then apply each folder name to the sub-command (Get-ChildItem -Path $proj -Recurse -File |…) line, injecting each line from the CVS file and log the last modified file in the a new CSV file for report.
$drivePath = “c:\temp\test”
$reportdate = Get-Date -Format “MM-dd-yy”
$serverpath = $drivePath.trimstart(“\”)
$servpath = split-path c:$serverpath -leaf
get-childitem -path $drivePath -Directory | select fullName | export-csv c:\temp\projlist.csv -NoTypeInformation
$projlist = Get-Content -Path c:\temp\projlist.csv
ForEach ($proj in $projlist) {Get-ChildItem -Path $proj -Recurse -File | Where-Object {($.LastWriteTime -gt (Get-Date).AddMonths(-1) )} | Sort-Object -Descending -Property LastWriteTime | select -First 1 FullName, LastWriteTime | Export-Csv "c:\temp\Report$servpath.csv" -append -NoTypeInformation }
When I run this script, I’m getting the following error:
Get-ChildItem : Illegal characters in path.
At C:\Users\tett\Documents\Test_script-SP.PS1:14 char:1
- Get-ChildItem -Path $proj -Recurse -File | Where-Object {($_.LastWrit …
-
+ CategoryInfo : NotSpecified: (:) [Get-ChildItem], ArgumentException + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.GetChildItemCommand
Get-ChildItem : A parameter cannot be found that matches parameter name ‘File’.
At C:\Users\tett\Documents\Test_script-SP.PS1:14 char:36
- Get-ChildItem -Path $proj -Recurse -File | Where-Object {($_.LastWrit …
any assistance with this script would be greatly appreciated and thanks in-advance.