Hi,
I recently started exploring powershell, thought i've been a fan of vba for a long time. So i found a script here for finding cluster resource status for one or multiple windows boxes which i found interesting and started to tweak it so i can perform more function
as per the needs. The problem i found was firstly i cant run the powershell from a noncluster or a desktop which i kind of figured on how to work around it and secondly instead of output to txt file i moved to getting output in csv so i can add some vba macro
to do multiple functions. Now while the output was in txt then everything was good but since i changed it to csv i just get the results of the last box in the list. So basically the output just saves data of the last server from my list. I read somewhere
that with upgrading to powershell 3.0 i can use append parameter which can resolve this issue. But is there any other way to get the desired results without updating the powershell version.
Below is the updated code i'm using
$SCRIPT_PARENT = Split-Path -Parent $MyInvocation.MyCommand.Definition $File = ($SCRIPT_PARENT + "\Cluster_Resource_Output.txt") $FileCSV = ($SCRIPT_PARENT + "\OutputinCsv.csv") $ClusterList = ($SCRIPT_PARENT + "\ClusterList.txt") Clear-Content $File, $FileCSV $Clusters = Get-Content $ClusterList # Cluster Names Write-Host "Please wait... Collecting Cluster Resources details... " -foregroundcolor "magenta" -backgroundcolor "yellow" Write-Host "$Clusters" -ForegroundColor Green foreach($Cluster in $Clusters) { $clugm = gwmi -ComputerName $cluster -Authentication PacketPrivacy -Namespace "root\mscluster" -Class MSCluster_Resource | add-member -pass NoteProperty Cluster $cluster | add-member -pass ScriptProperty Node ` { gwmi -namespace "root\mscluster" -computerName $this.Cluster -Authentication PacketPrivacy -query "ASSOCIATORS OF {MSCluster_Resource.Name='$($this.Name)'} WHERE AssocClass = MSCluster_NodeToActiveResource" | Select -ExpandProperty Name } | add-member -pass ScriptProperty Group ` { gwmi -ComputerName $this.Cluster -Authentication PacketPrivacy -Namespace "root\mscluster" -query "ASSOCIATORS OF {MSCluster_Resource.Name='$($this.Name)'} WHERE AssocClass = MSCluster_ResourceGroupToResource" | Select -ExpandProperty Name } $clugm | Select-Object cluster, Node, Name, @{n='State';e={if ($_.State -eq 2) {'Online'} else {'Offline'} }} | Export-Csv $FileCSV -notypeinformation #Output command >> Into CSV #$clugm | select cluster, Name, Node, @{n='State';e={if ($_.State -eq 2) {'Online'} else {'Offline'} }} | Ft -a | Out-File $File -Append #Output command >> Into textfile } $wshell.Popup("Completed..... Please run the verification", 0, "Cluster Resource", 48+4)
Thanks.