【发布时间】:2021-07-19 23:18:41
【问题描述】:
我仅限于 PowerShell 2。
我制作了下面的命令,列出了所有不是 NTFS 的文件系统,并且效果很好:
Get-WMIObject -Class Win32_Volume | Where-Object {$_.FileSystem -ne "NTFS"} | Select DriveLetter,Label,FileSystem
我需要在我的所有 Windows 系统上运行它,但是,我只想检查我的 Windows 2012(包括 R2)机器。例如,该命令针对所有 Windows 机器运行,对于 OS 2012(包括 R2)的机器,列出上面的命令输出以及其他操作系统类型,例如 Win 7、2016 等。 echo this "This is a Win 2012仅检查”。
PowerShell 可以实现上述目标吗?
编辑:
我快到了!我制作了以下内容:
$x = Get-WMIObject -Class Win32_OperatingSystem | Select Caption; if ($x -eq "Microsoft Windows Server 2012 Standard"){Get-WMIObject -Class Win32_Volume | Where-Object {$_.FileSystem -ne "NTFS"} | Select DriveLetter,Label,FileSystem}if ($x -eq "Microsoft Windows Server 2012 R2 Standard"){Get-WMIObject -Class Win32_Volume | Where-Object {$_.FileSystem -ne "NTFS"} | Select DriveLetter,Label,FileSystem}else {write-host("This applys to Windows 2012 Only")}
但即使我在 win 2012 机器上运行它,它也会与 else 语句相呼应,关于该语句可能有什么问题的任何想法?
【问题讨论】:
-
我向您推荐 WMI 类 Win32_OperatingSystem。
-
感谢 Jeff 强调 OS 类。不知道能不能在代码中输入IF/ELSE类型的语句来做我想做的事?
-
当然。您可能想收藏并探索 SS64 on PowerShell,记住 PowerShell 2 已过时。
-
首先,停止尝试使其成为单线;虽然它可以是单线的,但你最好将它作为一个多步骤的过程来解决,并确保它以这种方式工作,然后,尝试使用管道将东西折叠在一起。
-
@Help 将
...| Select Caption更改为...| Select -Expand Caption
标签: windows powershell command