#Function to get the computerlist: Name,OS,IPv4, IPv6,DiskInfo
function Get-ComputerListnDiskInfo{
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline=$True)] [string[]]$ComputerName
)
BEGIN {
Import-Module ActiveDirectory -Cmdlet Get-ADComputer -ErrorAction SilentlyContinue
}
PROCESS {
try{
$computerinfo = Get-ADComputer -Filter * -Properties OperatingSystem
#Information about Name,Ipv4,IPv6,Device,VolumeName,Free,Busy,Size,Pfree,Pbusy for ALL COMPUTERS container
$AllComputerInfo = @()
foreach ($comp in $computerinfo){
#Testing if computers is ON LINE
$TestCon = Tester $comp.name
$test = $TestCon.BooleanV
if($test) {
#write-output "$Test"
$PhysicalDisks = Get-WMIObject -computername $comp.name -query "SELECT * from win32_logicaldisk where DriveType = 3" | Select Deviceid,VolumeName,FreeSpace,Size
$Target = @()
#Create the Object foreach disk and append in the Target Variable
$GetOPNHealthStatus = Get-PhysicalDisk | select FriendlyName,OperationalStatus,HealthStatus
Write-Output "$PhysicalDisk.count"
#write-output $GetOPNHealthStatus.OperationalStatus
$i=0
foreach ($disk in $physicalDisks){
#Get all Items: size,free,busy,pfree and pbusy disk space info (can add a number at the end to set decimals)
$Size=FormatNSetSizeFreeSpace $disk.Size
$Free=FormatNSetSizeFreeSpace $disk.FreeSpace
$Busy=FormatNSetBusySpace $disk.Size $disk.FreeSpace
$Pfree=PercentFreeBusy $Free $size
$PBusy=PercentFreeBusy $Busy $size
#Create a new Object using all the info
$result =New-Object PSObject -Property @{
Device=$disk.DeviceID
VolumeName=$disk.VolumeName
Size=$Size
Free=$Free
Busy=$Busy
Pfree = $PFree
PBusy = $PBusy
OPStatus = $GetOPNHealthStatus.OperationalStatus[$i]
HStatus = $GetOPNHealthStatus.HealthStatus[$i]
}
$i++
#add this info to the target array
$Target+= $result
}
#Add all info into new object
$allIComnDiskInfo=New-Object PSObject -Property @{
Name = $comp.Name
OS = $comp.OperatingSystem
IPV4 = $TestCon.IPv4
IPV6 = $TestCon.IPv6
disksInfo = $Target
}
#and Fill any just add this info to the $Allcomputer info (just online computer's)
$AllComputerInfo+= $allIComnDiskInfo
}
}
return $AllComputerInfo
}
Catch{
Write-Warning $_.Exception.Message
}
}
}
$test = Get-ComputerListnDiskInfo
$test = Get-ComputerListnDiskInfo
$测试
disksInfo : {@{PBusy=8,148; VolumeName=; Busy=10,306; Pfree=91,853; Free=116,178; Device=C:; Size=126,483; OPStatus=O; HStatus=H}}
Name : DC2012
OS : Windows Server 2012 R2 Standard
IPV4 : 192.168.1.251
IPV6 : fe80::cd63:76bf:3d2b:340f%12
运行
$test | Export-Csv here.csv
我得到这个:
#TYPE System.String
"Length"
"6"
为什么会发生这种情况?
为什么我没有得到所有这些信息?
我应该如何查找包含在“DISKINFO”变量信息
我想这个$测试变量传递到另一个功能格式化它,它似乎并没有工作:
谢谢你提前答案
嗯,如果你刚刚说的是正确的 那么,为什么当我运行$测试有正确的信息。 据我所知,当你运行它没有参数他们将默认。我会将$ computername更正为$ computerInfo。我没有参数运行它,因为她会得到过程中的信息,因此不需要该参数。 $测试包含此: disksInfo:{@ {PBusy = 8,148;卷名=;忙= 10306; Pfree = 91853;免费= 116178;设备= C :;尺寸= 126483; OPStatus = O; HStatus = H}} 名称:DC2012 操作系统:Windows Server 2012 R2标准版 IPV4:192.168.1。251 IPV6:... – 2014-09-02 21:30:23
它仍然有正确的信息,它只是不存储在你可以很容易地访问它的方式,如你所愿。我有一种感觉,'$ test [1]'可能有你想要的,并且可以像你想要的那样通过管道输出到csv。 – TheMadTechnician 2014-09-02 21:34:07
你是对的@TheMadTechnician,$ test [1] |导出-csv here.csv工作... 现在我得到这个:“disksInfo”,“Name”,“OS”,“IPV4”,“IPV6” “System.Object []”,“DC2012” ,“Windows Server 2012 R2 Standard”,“192.168.1.251”,“fe80 :: cd63:76bf:3d2b:340f%12” 我想导出Diskinfo信息以及... – 2014-09-02 21:38:28