我在PowerShell脚本中有以下变量
$Buildlog="FormalBuild.log"
$Logger="/flp1:Append;LogFile=$Buildlog;Verbosity=Diag;"
#Logger will use Formalbuild.log
Write-host $logger
$Buildlog="Dailybuild.log"
#Logger should use Dailybuild.log file
Write-host $logger
$ logger始终显示Formalbuild.log。我不想再重新定义记录器。有没有办法让$ logger值动态化?
答案 0 :(得分:2)
请在此处查看示例:http://powershell.com/cs/blogs/tips/archive/2011/10/31/creating-intelligent-variables.aspx
然后代码段可能是:
$Buildlog="FormalBuild.log"
$logger = Set-PSBreakpoint -Variable logger -Mode Read -Action { $global:logger = "/flp1:Append;LogFile=$Buildlog;Verbosity=Diag;" }
#Logger will use Formalbuild.log
Write-host $logger
$Buildlog="Dailybuild.log"
#Logger should use Dailybuild.log file
Write-host $logger