I am trying to execute below PowerShell script to audit a file share for filenames starting with S. This script is executed by a SQL job every 10 seconds.
Script also tries to create a Log file each day and appends the data.
Script:
$svcs = Get-ChildItem -Path "\\XYZ\1100\ARCHIVE" | ?{ $_.name.StartsWith("S") } $filepath = "D:\Audit_1100\" + (date -f yyyy-MM-dd) + "_ArchiveAudit.txt" $svcs | select-object LastWriteTime,Name | sort LastWriteTime | out-file -append $filepath
Problem : I see below error while executing the script. Could you please advise what is missing here ?
A job step received an error at line 1 in a PowerShell script. The corresponding line is '$svcs = Get-ChildItem -Path "\\XYZ\1100\ARCHIVE" | ?{ $_.name.StartsWith("S") } $filepath = "D:\Audit_1100\" + (date -f yyyy-MM-dd) + "_ArchiveAudit.txt" $svcs | select-object LastWriteTime,Name | sort LastWriteTime | out-file -append $filepath'. Correct the script and reschedule the job. The error information returned by PowerShell is: 'A positional parameter cannot be found that accepts argument '$null'. '. Process Exit Code -1. The step failed.
Additional Error Details :
Where-Object : A positional parameter cannot be found that accepts argument 'D:\Audit_1100\2015-02-06_ArchiveAudit.txt'.
At line:1 char:63
+ $svcs = Get-ChildItem -Path "\\XYZ\1100\ARCHIVE" | ?{ $_.name.ToLower ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Where-Object], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.WhereObjectCommand
- Edited by KiranAitha Friday, February 06, 2015 11:32 PM