我写了几篇powershell命令来对HyperV集群执行一些审计。该命令工作正常,但任何人都可以帮我修剪输出,以便我可以收集我需要的东西吗?
##Audit-CreatingDC
$AuditDC = Invoke-Command -ComputerName $ComputerName {Get-ChildItem -Path HKLM:\cluster\resources -recurse | get-itemproperty -name CreatingDC -erroraction 'silentlycontinue'}| ft CreatingDC,PSComputerName
####Audit-iSCSI
#Show which hosts are not communicating to the storage with the ‘-s’ and where there are duplicated targets:
$AuditISCSI = Invoke-Command -ComputerName $ComputerName { get-iscsisession } | FT PSComputerName, InitiatorPortalAddress, IsConnected -autosize
######Discover checkdsk errors - "Scan Needed". Execute using txt of one node from each cluster.
$AuditCHKDSK = Invoke-Command -ComputerName $ComputerName { get-volume | Where-Object –FilterScript { $_.HealthStatus -eq "Scan Needed" }} | FT PSComputerName, FileSystem, HealthStatus -autosize
每个的输出低于
CreatingDC PSComputerName
---------- --------------
\\dc-sc-02.oim.corp.com slcoc037
PSComputerName InitiatorPortalAddress IsConnected
-------------- ---------------------- -----------
slcoc037 10.214.61.107 True
PSComputerName FileSystem HealthStatus
-------------- ---------- ------------
slcoc037 CSVFS 1
但是我需要这种格式的输出
\\dc-sc-02.oim.corp.com
10.241.81.107
CSVFS 1
任何人都可以帮我修剪这三个命令吗?
答案 0 :(得分:0)
您可能已经知道几乎所有的PowerShell输出都是对象。对象具有属性。显示特定属性将使用语法$Object.Propertyname
。在您的情况下,CreatingDC
是$AuditDC
Variable对象的属性。应用该逻辑,您需要做的就是这样显示:
$AuditDC.CreatingDC
$AuditISCSI.InitiatorPortalAddress
$AuditCHKDSK.FileSystem