Pra*_*hag 5 registry powershell
我试图了解Windows计算机是否需要重新启动。但是,我的脚本抛出了错误。
powershell "$key = Get-Item "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" -ErrorAction SilentlyContinue"
Error :
Get-Item : A positional parameter cannot be found that accepts argument
'Update\RebootRequired'.
At line:1 char:8
+ $key = Get-Item
HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Aut ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
+ CategoryInfo : InvalidArgument: (:) [Get-Item], ParameterBindin
gException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell
.Commands.GetItemCommand
Run Code Online (Sandbox Code Playgroud)
我在“命令提示符”中运行此命令。不知道是什么意思!
小智 10
您需要检查 2 个路径,一个键,并且您需要通过查询配置管理器WMI以检查所有可能的位置。
#Adapted from https://gist.github.com/altrive/5329377
#Based on <http://gallery.technet.microsoft.com/scriptcenter/Get-PendingReboot-Query-bdb79542>
function Test-PendingReboot {
if (Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending" -EA Ignore) { return $true }
if (Get-Item "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" -EA Ignore) { return $true }
if (Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager" -Name PendingFileRenameOperations -EA Ignore) { return $true }
try {
$util = [wmiclass]"\\.\root\ccm\clientsdk:CCM_ClientUtilities"
$status = $util.DetermineIfRebootPending()
if (($status -ne $null) -and $status.RebootPending) {
return $true
}
}
catch { }
return $false
}
Test-PendingReboot
Run Code Online (Sandbox Code Playgroud)
Geo*_*dze 10
待重启可能是由多种原因引起的,而不仅仅是其他答案中详述的原因。尝试PendingReboot模块,该模块将各种测试合并到一个cmdlet中:
# Install
Install-Module -Name PendingReboot
# Run
Test-PendingReboot -Detailed
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
26092 次 |
| 最近记录: |