Reputation: 49
Not much to explain just watch.
$env = '@PROD'
$LogTime = Get-Date -Format "MM-dd-yyyy_hh:mm:ss"
$LogFile = '"C:/Test/test/test/Log/"+$LogTime+"_Log_"+$env+".log"'
Write-Host $LogFile
But the $LogFile isn't right. Output = "C:\Test\test\test\Log\"+$LogTime+"Log"+$env+".log"
Upvotes: 1
Views: 56
Reputation: 19634
You're over-complicating things; I'd suggest using string expansion. Also, $env
is a bad variable name as it matches the scope modifier name, and colons (:
) are not valid characters in Windows' file structures.
$Environment = '@PROD'
$LogTime = Get-Date -Format 'MM-dd-yyyy_hh.mm.ss'
## Alternatively, ${Environment} for clarity
$LogFile = "C:\Test\test\test\Log\${LogTime}_Log_$Environment.log"
Write-Host $LogFile
Upvotes: 5