2013-12-20 78 views
0

我可以添加什么来使它在完成后从头开始?完成时的循环脚本

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; 
+0

把它放在一个循环 – user1336827

+0

不知道如何,这就是为什么我问。 – Aaron

+0

你想让它继续从头开始吗? – user1336827

回答

2

您可能需要检查“$ 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; 
} 
+1

已更新它我猜 - 应该工作。 – user1336827

+0

它保持循环相同的变量,而不是要求一个新的和输入q或Q退出不起作用。 – Aaron

+0

那里试试吧,先移动$ tag =“”,而 – user1336827