简体   繁体   中英

How do I insert comma or replace space with comma in string variable?

Hi when I run the command: Get-XASession -Full -ServerName myserver01 | select SessionId,SessionName,AccountName,ServerName,LogOnTime,DisconnectTime,State,ConnectTime,BrowserNam | ft -auto Get-XASession -Full -ServerName myserver01 | select SessionId,SessionName,AccountName,ServerName,LogOnTime,DisconnectTime,State,ConnectTime,BrowserNam | ft -auto

I get among other things other things ConnectTime in this format: 9/1/2014 3:56:17 AM

When I export this into to a csv and import it to Excel I need to do some manual steps to separate columns like this. Is there an easy easy to replace space in this variable(?) with a comma?

Or if there is any xenapp powershell gurus who see this there might even be a command that gives you the date/time in a better format.

//Fredrik Thanks

Maybe this is something you can use:

$Date = Get-Date
$ModifiedDate = $Date -replace(" ",",")
Write-Host "ModifiedDate contains: $ModifiedDate"

You can also export with another Delimiter like a semicolon:

$Stuff | Export-Csv -Path 'C:\Test.csv' -Delimiter ';' -NoTypeInformation

尝试这个:

Get-XASession -Full -ServerName myserver01 | select SessionId,SessionName,AccountName,ServerName,LogOnTime,DisconnectTime,State,@{n='ConnectTime';e={$_.connectTime -replace ' ',','}},BrowserNam

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM