我对PowerShell不太了解,但是我想知道如何将脚本的输出(以下摘录)写入本地目录中的文件中,而不是写入屏幕中?
{
$userEntry = $result.GetDirectoryEntry()
Write-Host "User Name = " $userEntry.name
foreach ($SPN in $userEntry.servicePrincipalName)
{
Write-Host "SPN = " $SPN
}
Write-Host ""
}
答案 0 :(得分:0)
使用Write-Host
参数将Out-File
替换为-Append
:
{
$userEntry = $result.GetDirectoryEntry()
"User Name = $($userEntry.name)" | Out-File Output.txt -Append
foreach ($SPN in $userEntry.servicePrincipalName)
{
"SPN = $SPN" | Out-File Output.txt -Append
}
"" | Out-File Output.txt -Append
}
Out-File
将直接写入文件,Tee-Object
将同时输出到屏幕和到文件。