2017-10-09 32 views
0

我已经写了几个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 

谁能帮我修剪这些3个命令?

+0

$ AuditDC.CreatingDC,$ AuditISCSI.Initia ..... – guiwhatsthat

回答

0

您可能已经知道几乎所有的powershell输出都是对象。对象具有属性。显示特定属性将使用语法$Object.Propertyname。在你的情况下,CreatingDC$AuditDC变量对象的属性。运用这个逻辑,所有你需要做的是,像这样显示出来:

$AuditDC.CreatingDC 
$AuditISCSI.InitiatorPortalAddress 
$AuditCHKDSK.FileSystem 
+0

我尝试这样做,我没有得到任何输出,这 – Sandeep

+0

我没有注意到这一点。还要将每行上的“FT”更改为“Select-Object”。 –

+0

谢谢Rohin。它现在有效 – Sandeep