我使用下面提到的VBScript从多个服务器收集MPIO磁盘活动路径信息。我试图将VBScript转换为PowerShell模块,但无法找到合适的类或按预期获取值。
Dim oFSO, oTSIn, oTSOut
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oTSOut = oFSO.CreateTextFile("results.txt")
Set oTSIn = oFSO.OpenTextFile("servers.txt")
Do Until oTSIn.AtEndOfStream
sServerName = oTSIn.ReadLine
intFreeSpace6=sServerName
oTSOut.WriteLine intFreeSpace6
On Error Resume Next
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
Dim wmi
Set wmi = GetObject("winmgmts://" + sServerName + "/root/WMI")
Dim mpio_disks
Set mpio_disks = wmi.ExecQuery("SELECT * FROM MPIO_DISK_INFO")
For Each disk In mpio_disks
Dim mpio_drives
mpio_drives = disk.DriveInfo
For Each drive In mpio_drives
Dim name
name = drive.Name
Dim paths
paths = drive.NumberPaths
Dim space
space="= "
oTSOut.WriteLine name & space & paths
'WScript.Echo name & paths
Next
Next
Loop
oTSIn.Close
oTSOut.Close
MsgBox "Finished!"
PowerShell命令尝试在下面,但无法获取路径信息:
$MPIODisks = Get-WmiObject -Namespace "root\wmi" -Class mpio_disk_info -ComputerName "$Server" |
Select-Object "DriveInfo"
Write-Host "Host Name : " $Server
foreach ($Disk in $MPIODisks) {
$mpiodrives = $disk.DriveInfo
foreach ($Drive in $mpiodrives) {
Write-Host "Drive : " $Drive.Name
Write-Host "Path : " $Drive.Numberpath
}
}
如下所述提供输出:
Drive : MPIO Disk0
Path :
Drive : MPIO Disk1
Path :
Drive : MPIO Disk2
Path :
Drive : MPIO Disk3
Path :
Drive : MPIO Disk4
Path :
Drive : MPIO Disk6
Path :
Drive : MPIO Disk7
Path :
Drive : MPIO Disk8
Path :
Drive : MPIO Disk10
Path :
答案 0 :(得分:0)
(gwmi -Namespace root \ wmi -Class mpio_disk_info).driveinfo | %{Write-host"名称:$($ .name)路径:$($ .numberpaths)"}