Reputation: 63
Running the following ps1 but the datetime parameter is resuting in an error.
Debug shows the date is correct ($earlydate = the date I entered)
The HostIP parameter is being passed so it seems there is a special trick necessary for passing the datetime that I don't know.
The error I receive is:
Cannot validate argument on parameter 'After'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
Any help is greatly appreciated.
param(
[Parameter(Mandatory=$True)]
[string]$HostIP,
[Parameter(Mandatory=$True)]
[datetime]$earlydate,
[Parameter(Mandatory=$True)]
[datetime]$latedate
)
Invoke-Command {Get-EventLog Security -After $earlydate -Before $latedate} -ComputerName $HostIP |
Export-Csv c:\Events\$HostIP.csv
Upvotes: 0
Views: 1406
Reputation: 1346
Invoke-Command {Get-EventLog Security -After $using:earlydate -Before $using:latedate}
$earlydate & $latedate variable is defined on your machine not on remote machine. Remote machine doesn't inherit the variables automatically, so variable on the remote machine will be null.
Upvotes: 1
Reputation: 917
Your script is looking for a datetime type and I am thinking you are passing in a string. If you want to pass in a string convert it to datetime inside your function otherwise pass in a datetime object such as:
(Get-Date -year 2017 -month 9 -day 15)
Upvotes: 0