我试图了解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)
我在“命令提示符”中运行此命令。不知道是什么意思!
我尝试使用下面的脚本获取物理 CPU 的数量,但无法获得所需的结果。
get-wmiobject Win32_ComputerSystem
Run Code Online (Sandbox Code Playgroud)
有没有命令可以获取物理CPU的数量?
我正在尝试获取 ip 地址和 mac 地址。下面的代码工作得很好,但不适用于 Windows R2,有人有什么建议吗?
主要IP
(get-WmiObject Win32_NetworkAdapterConfiguration|Where {$_.Ipaddress.length -gt 1}).IPAddress | Select-object -index 0
Run Code Online (Sandbox Code Playgroud)
主 MAC:
(Get-WmiObject Win32_NetworkAdapterConfiguration | where {$_.ipenabled -EQ $true}).Macaddress | select-object -first 1
Run Code Online (Sandbox Code Playgroud) 我编写了Python代码来进行一些计算.在此期间它转换string为float.但是有时数字字符串值可能是空的,它给我的时间valueError.我试图在try catch块中保留它,但是它会转到另一个异常块,如下所示.
try:
float(some value)
except Exception as ValueError:
print(error message)
except Exception as oserror:
print(mesage)
Run Code Online (Sandbox Code Playgroud)
它转到os错误块而不是ValueError块