Loops 完成时循环脚本
完成后,我可以添加什么来从头开始Loops 完成时循环脚本,loops,powershell,Loops,Powershell,完成后,我可以添加什么来从头开始 mode con: cols=35 lines=5 $tag1 = "" while (-not ($tag1)) { $tag1 = Read-Host 'Enter tag # or Q to quit' } mode con: cols=80 lines=46 cls sc.exe \\$tag1 start RemoteRegistry; cls start-sleep -seconds 2
mode con: cols=35 lines=5
$tag1 = ""
while (-not ($tag1)) {
$tag1 = Read-Host 'Enter tag # or Q to quit'
}
mode con: cols=80 lines=46
cls
sc.exe \\$tag1 start RemoteRegistry;
cls
start-sleep -seconds 2
cls
$OSInfo = get-wmiobject -class win32_operatingsystem -computername $tag1;
$OSInfo | Format-Table -Property @{Name="OS Name";Expression={$_.Caption}} -AutoSize;
$OSInfo | Format-Table -Property @{Name="System Boot Time";Expression={$_.ConvertToDateTime($_.LastBootUpTime)}} -AutoSize;
$OSInfo | Format-Table -Property @{Name="OS Install Date";Expression={$_.ConvertToDateTime($_.InstallDate)}} -AutoSize;
"`n"
"Current Date & Time: $(Get-Date -Format G)";
"`n"
Get-WmiObject win32_computersystem -Computer $tag1 | Format-Table -Property @{Name="Username";Expression={$_.username}} -Autosize;
Get-EventLog system -computername $tag1 -InstanceId 2147489657 -Newest 10 | format-table EventID,TimeWritten,MachineName -AutoSize;
您可能需要检查“$tag!='Q'”上的语法,但基本上,在输入Q之前,这应该会继续要求您输入标记
mode con: cols=35 lines=5
while ($tag -ne "Q"){
$tag1 = ""
while (-not ($tag1)) {
$tag1 = Read-Host 'Enter tag # or Q to quit'
}
if($tag1 -eq "Q"){break}
mode con: cols=80 lines=46
cls
sc.exe \\$tag1 start RemoteRegistry;
cls
start-sleep -seconds 2
cls
$OSInfo = get-wmiobject -class win32_operatingsystem -computername $tag1;
$OSInfo | Format-Table -Property @{Name="OS Name";Expression={$_.Caption}} -AutoSize;
$OSInfo | Format-Table -Property @{Name="System Boot Time";Expression={$_.ConvertToDateTime($_.LastBootUpTime)}} -AutoSize;
$OSInfo | Format-Table -Property @{Name="OS Install Date";Expression={$_.ConvertToDateTime($_.InstallDate)}} -AutoSize;
"`n"
"Current Date & Time: $(Get-Date -Format G)";
"`n"
Get-WmiObject win32_computersystem -Computer $tag1 | Format-Table -Property @{Name="Username";Expression={$_.username}} -Autosize;
Get-EventLog system -computername $tag1 -InstanceId 2147489657 -Newest 10 | format-table EventID,TimeWritten,MachineName -AutoSize;
}
不知道怎么做,这就是我问的原因。你想让它永远重新开始吗?脚本要求计算机系统名。我输入它,它会告诉我计算机信息,但一旦它告诉我信息,它就会快速关闭。我希望它完成后再索要$tag1。因此,我不必一次又一次地打开它。它不断循环相同的变量,而不是要求一个新变量,并且键入q或q退出不起作用。现在试试,在第一个whileYeah中移动$tag=“”,效果很好。唯一的问题是,q和q退出不起作用。嗯,试试看,对不起,我从来没有真正使用过powershell,我在脚本中添加了一个检查标记是否为Q,我正在考虑添加它。似乎已经解决了所有问题。谢谢你以前没用过,但知道命令吗?它和你能比较的东西有什么相似之处?