Reputation: 7397
In powershell if I run Get_Date
by itself it will give me the correct date. But in my script when I run
"$computer" + "_Already_Had_Software_" + "(Get-Date)" | Out-File -FilePath "\\server\Install\Office2010\RemoteInstallfile.txt" -Append
It does not show the date but just says
_Already_Had_Software_Get-Date
Instead of showing the actual date.
Will someone please tell me where I may be going wrong?
Upvotes: 1
Views: 180
Reputation: 7638
You should be using "$(Get-Date)"
. Your string forgot the $
that tells powershell to execute it.
Alternates:
"${computer}_Already_Had_Software_$(Get-Date)"
"$computer" + "_Already_Had_Software_" + (Get-Date)
({0}_Already_Had_Software_{1} -f $computer, (Get-Date))
[String]::Join('_', ($computer, 'Already_Had_Software', (Get-Date)))
Upvotes: 2
Reputation: 980
Use this :
$date = Get-Date -Format "yyyy-MM-dd --- hh-mm-ss-fff tt Zone K" | Out-String
"$computer" + "_Already_Had_Software_" + "$date" | Out-File -FilePath "\\server\Install\Office2010\RemoteInstallfile.txt" -Append
Upvotes: 1