I'm writing files with PowerShell to store specific information in it. I also want to create windows event log entries to check if the file which was "newly" created is really there.
New-EventLog -LogName System -Source "Files I store information in"
Write-EventLog -LogName System -Source "Files I store information in" -EntryType Information -EventId 1 -Message "Information written to file script started"
$FilePath = "C:\Path\Files"
command.exe -Out-File $FilePath\${env:computername}_$(get-date -f dd-MM-yyyy-hhmm).file
Basically I'm searching for a way to verify if the above command.exe created a file. I'm not sure how to do that when I'm using the "get-date" option to append this to the file name. If the file was created I want to create a successful event log entry. If it wasn't created I want to create a non successful event log entry.
Anyone a hint on this ?
$fileName = "$FilePath\${env:computername}_$(get-date -f dd-MM-yyyy-hhmm).file"
), run your command with its output (command.exe -Out-File $fileName
) and then check if the file exists usingTest-Path -Path $fileName
. – notjustme