2012-04-09 255 views
0

我已經寫了下面的代碼,除了其中一個變量超過200個字符之外,它能夠正常工作並進入下一行,將佈局搞亂。任何關於更好佈局的建議,如果其中一個變量很長,它仍然保留結構?powershell寫入日誌文件

$WriteLog = $null 
$WriteLog = @() 
$WriteLog +="Here is some stuff:    $stuff1" 
$WriteLog +="Here is some stuff:    $stuff2" 
$WriteLog +="Here is some stuff:    $stuff3" 
$WriteLog +="Here is some stuff:    $stuff4" 
$WriteLog +="Here is some stuff:    $stuff5" 
$WriteLog +="Here is some stuff:    $stuff6" 
Out-File -InputObject $WriteLog -Append -NoClobber -FilePath "$env:SystemDrive\somestuff\somestuff.txt" 

輸出示例:

"Here is some stuff:     stuff1" 
"Here is some stuff:   stuff2" 
"Here is some stuff:    Heres a lot of stuff 
stuff3, stuff3, stuff3, stuff3, stuff3, stuff3" 
"Here is some stuff:   stuff4" 
"Here is some stuff:     stuff5" 
"Here is some stuff:     stuff6" 
+0

正如你可以看到ive用一個例子更新了原來的問題。直到「這裏有很多東西 stuff3」,然後它會包裝到下一行。我希望所有東西都適合,如果它包裝到下一行,再次證明stuff1是正確的。希望我現在多做一點。謝謝 – resolver101 2012-04-12 19:15:49

回答

1

,如果你不知道(我希望我理解您的問題),我會用格式化。見

'{0,5} -f 5 
#vs. 
'{0,5} -f 1115 

然後..

$WriteLog = $stuff1, $stuff2, $stuff3, $stuff4, $stuff5, $stuff6 | 
       Foreach-Object { "Here is some stuff:{0,20}" -f $_ } 
$WriteLog = $WriteLog -join "`n" 
1

出文件中有-Width參數可能的幫助。或者你可以格式化長變量作爲這裏的字符串?