Quantcast
Channel: VMware Communities : Discussion List - All Communities
Viewing all articles
Browse latest Browse all 193198

Removing Headers

$
0
0

Hi I have this code that is walking the datastores. I have the data put into a hash table. I want the labels but only once. It appears to put the headers in for any datastore that has the criteria i am searching for. I include the code for reference. I was wondering how i could get it to only put the header labels in the output csv only once. Any assistance would be great.

 

 

 

$DTE = Get-Date -Format MMddyyyy
$Report = ($global:DefaultVIServers).Name
$ReportName = "SnapShotAudit_" + $Report + "_" + $DTE + ".csv"
$clstr = get-cluster
foreach ($VMH in $Clstr)
{
    $esxHost = (get-cluster -Name $VMH | get-vmhost | Select-object -First 1).Name
    $DatStr = (get-datastore -vmhost $esxHost | where-object {$_.Name -notmatch "DoNotUse*"}).DatastoreBrowserPath
    foreach ($STR in $DatStr)
    {
        write-host Scanning "$STR Please wait until complete."
        $Dat = get-childitem $STR -recurse | where-object {$_.Name -like "*0000*.vmdk"} | select-object @{Label="File Name"; e={$Itm.Name}}, @{Label="Size"; e={$Itm.Length}}, @{Label="Last Write Time"; e={$Itm.LastWriteTime}}, @{Label= "DataStore Name"; e={$Itm.Datastore}}, @{Label= "Folder Name"; E={$Itm.FullName}} | convertto-csv -UseCulture -NoTypeinformation | out-file c:\$ReportName -append
       
    }
}


Viewing all articles
Browse latest Browse all 193198

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>