# exporting to filename with timestamp part of filename

• ### Question

• objective:\to export a query  to a filename called c:\Temp\citrix adding the timestamp to filename
example C:\Temp\citrix 2018-02-05 01:30.csv

PS C:\temp> get-process |export-csv 'C:\Temp\citrix' + ((Get-Date).ToString('yyyy-MM-dd hh:mm')) + '.csv'

Export-Csv : A positional parameter cannot be found that accepts argument '2018-02-05 01:38'.
At line:1 char:24
+ get-process |export-csv <<<<  'C:\Temp\citrix' + ((Get-Date).ToString('yyyy-MM-dd hh:mm')) + '.csv'
+ CategoryInfo          : InvalidArgument: (:) [Export-Csv], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.ExportCsvCommand

What am I scripting wrong?

if I run ((Get-Date).ToString('yyyy-MM-dd hh:mm')) + '.csv' I get 2018-02-05 01:30.csv

Monday, February 5, 2018 6:58 PM

• Because you cannot use : in folder or file names

If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join'' • Proposed as answer by Monday, February 5, 2018 7:25 PM • Marked as answer by Tuesday, February 6, 2018 6:11 PM Monday, February 5, 2018 7:07 PM ### All replies • Because you cannot use : in folder or file names If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''

• Proposed as answer by Monday, February 5, 2018 7:25 PM
• Marked as answer by Tuesday, February 6, 2018 6:11 PM
Monday, February 5, 2018 7:07 PM
• So you are stating this cannot be done?

if I run ((Get-Date).ToString('yyyy-MM-dd hh:mm'))  I get >> 2018-02-05 01:30.csv

Monday, February 5, 2018 8:00 PM
• You can do that all day in Powershell to display a name as you are just creating a string object, but once you try to create the file it will fail.

https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396

Use any character in the current code page for a name, including Unicode characters and characters in the extended character set (128–255), except for the following:

• The following reserved characters:

• < (less than)
• > (greater than)
• : (colon)
• " (double quote)
• / (forward slash)
• \ (backslash)
• | (vertical bar or pipe)
• ? (question mark)
• * (asterisk)

If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join'' • Edited by Monday, February 5, 2018 8:05 PM typo Monday, February 5, 2018 8:03 PM • it is doable afterall - thanks to my colleague rm here is the script$Filename = 'C:\Temp\citrix' + ((Get-Date).ToString('yyyy-MM-dd hh mm')) + '.csv'

get-xasession -farm | select accountname, browsername, clientname, logontime | sort browsername | EXPORT-CSV $filename Tuesday, February 6, 2018 5:07 PM • OK?? Your colleague removed the : from ToString('yyyy-MM-dd hh:mm') which is what I said was causing your issue as it is an invalid character. If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''

Tuesday, February 6, 2018 5:13 PM