我在powershell和Tee-Object
中的此代碼無法將所有Write-Host
命令保存到file.txt。我能做些什麼來修復這些代碼?Tee-Object無法將輸出命令註釋保存到文件
Import-Module ActiveDirectory
Add-Type -AssemblyName System.Web
$users = Get-Content -Path 'G:\Shares\xx xxx\ResetPassword\UserList.txt'
ForEach ($user in $users)
{
$unsecuredpwd = [System.Web.Security.Membership]::GeneratePassword(10, 3)
$password = ConvertTo-SecureString -AsPlainText $unsecuredpwd -Force
Get-ADUser $user | Set-ADAccountPassword -NewPassword $password -Reset
Get-ADUser $user | Set-AdUser -ChangePasswordAtLogon $true
Enable-ADAccount -Identity $user
Write-Host 「uzytkownik: $user」
Write-Host 「haslo: $unsecuredpwd」
Write-Host 「 `r`n`r`n」
} | Tee-Object -FilePath G:\Shares\xx xxx\ResetPassword\Output.txt
Read-Host -Prompt "click enter to exit"
什麼是你的輸出/什麼發球對象寫入文件? – restless1987
Tee-Object必須輸出用戶名併爲每個用戶生成密碼 –