Powershell检查远程电脑上的存储
你好,我正在构建一个菜单来运行每个所选选项的脚本,我想要的一个选项是检查远程电脑的存储,但通过研究,我已经破坏了脚本,希望能够从拥有超过一个月使用 PS 经验的人那里获得帮助。
Invoke-Command $Computer = Read-Host Please Enter Host name -ScriptBlock{Get-WmiObject -Class Win32_logicalDisk -Filter "DeviceID='C:'" | Select SystemName, DeviceID, @{n='Size(GB)';e={$_.size / 1gb -as [int]}},@{n='Free(GB)';e={$_.Freespace / 1gb -as [int]}}} > C:\DiskInfo_output.txt
Hello I am building a menu to run scripts per option selected and an option I want is to check storage of a remote pc but from researching I have broken the script and hopefully can get assistance from someone that has more than my month experience using PS.
Invoke-Command $Computer = Read-Host Please Enter Host name -ScriptBlock{Get-WmiObject -Class Win32_logicalDisk -Filter "DeviceID='C:'" | Select SystemName, DeviceID, @{n='Size(GB)';e={$_.size / 1gb -as [int]}},@{n='Free(GB)';e={$_.Freespace / 1gb -as [int]}}} > C:\DiskInfo_output.txt
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要将
$Computer = Read-Host ...
语句移出Invoke-Command
语句:You need to move the
$Computer = Read-Host ...
statement out of theInvoke-Command
statement:您不需要使用
Invoke-Command
,因为 WMI cmdlet 接受-ComputerName
值:或者,您可以首先使用分组提示输入计算机名称运算符(Santiago 在评论中指出):
旁注:
Get-WMIObject
等 WMI Cmdlet 已弃用,并已被较新的 CIM Cmdlet。Get-WmiObject -Class Win32_ologicalDisk -Filter "DeviceID='C:'"
Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DeviceID='C:'"
You don't need to use
Invoke-Command
seeing as the WMI cmdlets accept a-ComputerName
value:Alternatively, you can have the Computer Name input be prompted first using the grouping operator (as Santiago points out in the comments):
Side Note:
The WMI Cmdlets such as
Get-WMIObject
are deprecated and have been replaced by the newer CIM Cmdlets.Get-WmiObject -Class Win32_logicalDisk -Filter "DeviceID='C:'"
Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DeviceID='C:'"