如果我逐行运行PowerShell脚本,它就可以正常工作,但是当我尝试将脚本作为一个脚本运行时,对用户的搜索不会及时出现在下一个问题中。请让我知道我如何才能强制脚本的第三行出现,而不是要求以后的方式。
$name = Read-Host "What is the user's first name or letter?"
$list = Get-ADUser -Filter * | ? {$_.SamAccountName -match $name} | select SamAccountName | sort SamAccountName
$list
$DisableUser = Read-Host "Copy and paste the user here"
$t = $DisableUser
$year = Read-Host "Please input the year the user should be disabled, in this format (YYYY)"
$month = Read-Host "Please input the month the user should be disabled, in this format (MM)"
$day = Read-Host "Please input the day the user should be disabled, in this format (DD)"
$date = "$month/$day/$year"
$hour = Read-Host "Please input the hour of the day the user should be disabled, in this format (HH)"
$minute = Read-Host "Please input the minute the user should be disabled, in this format (MM)"
$seconds = Read-Host "Please input the second the user should be disabled, in this format (SS)"
$ampm = Read-Host "AM or PM?"
$Time = "${hour}:${minute}:${seconds} ${ampm}"
$dandt = "$date $Time"
$dandt
Write-host "$t will be disabled on this date, $dandt"
$answer = Read-Host "Is this correct? Please type Yes or No"
$l = $answer
If ($l -like "y*")
{Set-ADAccountExpiration $t -DateTime $dandt}
ELSE { "Exiting"; Return}发布于 2018-04-27 02:11:04
您正在合并输出流。Read-Host和Write-Host直接写入控制台,而$list和$dandt独立输出到标准输出。它们不同步是因为它们是不同的输出流。解决方案基本上是强制所有内容都通过一个流。因为您使用的是Read-Host,所以这意味着控制台流。
更改此设置:
$list其中之一:
$list | Format-Table -AutoSize | Out-String | Write-Host
$list | Format-List | Out-String | Write-Host还有这个:
$dandt要这样做:
Write-Host $dandt也就是说,这根本不是我写这样的东西的方式。我宁愿使用ADUC/ADAC而不是这个。
https://stackoverflow.com/questions/50048566
复制相似问题