Reputation: 1217
Why is it that this command is able to export and create a file in the current path but when I add the Get-Date cmdlet it suddenly fails?
Is the Get-Date cmdlet invoking some type of new environment?
Working command -
Get-Process | Sort-Object WorkingSet64 | Select-Object Name,@{Name='WorkingSet';Expression={($_.WorkingSet64/1MB)}} | Export-Csv -Path "processes64.csv" -Delimiter ","
Command breaks -
$Date = Get-Date -Format "MM-dd-yy-HH:MM"
Get-Process | Sort-Object WorkingSet64 | Select-Object Name,@{Name='WorkingSet';Expression={($_.WorkingSet64/1MB)}} | Export-Csv -Path "processes64$Date.csv" -Delimiter ","
Error message -
Export-Csv : Cannot find drive. A drive with the name 'processes64-06-28-16-15' does not exist. At line:3 char:120
- ... Set64/1MB)}} | Export-Csv -Path "processes64-$Date.csv" -Delimiter ","
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : ObjectNotFound: (processes6406-28-16-15:String) [Export-Csv], DriveNotFoundException
- FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.ExportCsvCommand
I'd just like to either export to a directory on the C drive or to the current working directory..
Upvotes: 1
Views: 2983
Reputation: 1217
I believe I figured it out, it's because of the colon in the date format. File names can't have colons..
But I'm still curious as to what Powershell is interpreting, the error message doesn't seem to have anything to do with an invalid file name.
Upvotes: 2