Jumping around to certain spots in script

后端 未结 3 1807
别那么骄傲
别那么骄傲 2021-02-07 16:45

Is there a way to make a script jump to a specific spot like :GOTO in command prompt? I wanted to make the script jump to the beginning when it is ended.

$tag1 =         


        
3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-07 17:00

    Another variation on the script with some ideas taken from @mjolinor. I also switched away from using systeminfo because at least on my computer, it's much slower than using the applicable WMI query.

    while (1) {
        $tag1 = Read-Host 'Enter tag # or Q to quit'
        if ($tag1 -eq "Q") {
            break;
        }
        sc.exe \\$tag1 start RemoteRegistry;
        start-sleep -seconds 2
        $OSInfo = get-wmiobject -class win32_operatingsystem -computername $tag1;
        $OSInfo | Format-Table -Property @{Name="OS Name";Expression={$_.Caption}},@{Name="System Boot Time";Expression={$_.ConvertToDateTime($_.LastBootUpTime)}},@{Name="System Uptime (Days)";Expression={[math]::Round((New-TimeSpan -Start $_.converttodatetime($_.LastBootUpTime)|select-object -expandproperty totaldays),2)}} -AutoSize;
        Get-EventLog system -computername $tag1 -InstanceId 2147489657 -Newest 10 | format-table EventID,TimeWritten,MachineName -AutoSize
    }
    

    I'm not certain that WMI needs remote registry, so you might be able to eliminate the sc.exe line and sleep altogether. Unless you need it for something else.

提交回复
热议问题