$VCHost = "1.2.3.4" $Vcuser = "administrator" $VCPassword = "mypass123" $WFA_install = "C:\Program Files\NetApp\WFA\" ###### Create the Logger Configuration WFA ###### #Load the assembley from your dll location $dllLocation= $WFA_install + "PoSH\Modules\DataONTAP\log4net.dll" [void][Reflection.Assembly]::LoadFrom($dllLocation) #Define your logging pattern. See more about it here: http://logging.apache.org/log4net/release/sdk/log4net.Layout.PatternLayout.html $pattern="%d %w %-5p %c : %m%n" #Reset the log4net configuration [log4net.LogManager]::ResetConfiguration() #Create the Logging file for every single Datasource based on the Hostname. $logFile= "C:\Temp\vmware.log" New-Item -Path $logFile -type file -Force #Create the log4net config Appender $Appender = new-object log4net.Appender.FileAppender $Appender.File = $logFile $Appender.Layout = new-object log4net.Layout.PatternLayout($pattern) $Appender.Threshold = [log4net.Core.Level]::All $Appender.ActivateOptions() [log4net.Config.BasicConfigurator]::Configure($Appender) #Create Logger for the DataSource Type Name. You can actually put anything $logg = [log4net.LogManager]::GetLogger("[VMware vCenter 6.0]") ###### Logger is ready ##### $logg.Info("====== Data Source acquisition begins now =======") $nasShareFile = "./Nas_Share.csv" [System.Threading.Thread]::CurrentThread.CurrentCulture="en-US" New-Item -Path $nasShareFile -type file -Force Add-PSSnapin VMware.VimAutomation.Core -ErrorAction Stop Connect-VIServer -Server $VCHost -Port 443 -User $Vcuser -Password $VCPassword -Protocol https $datacenters = Get-Datacenter foreach($datacenter in $datacenters) { #$logg.Info("For Datacenter $datacenter") $datacenterName = $datacenter.Name $dcDatastores = @() # putting datastore collection ahead of hosts collection as # host collection includes luns connection which uses the exntestovmfsdshash populated in # the datastore section Foreach($datastore in ($datacenter | Get-Datastore | ?{$_.Accessible})){ # gathering dc datastores for later us in vm section $dcDatastores += $datastore $datastoreName = $datastore.Name $capacityMB = $datastore.CapacityMB $freeSpaceMB = $datastore.FreeSpaceMB $datastoreId = $datastore.Id.GetHashCode() $type = $datastore.Type if($type -eq "NFS") { $nfsHost = $datastore.RemoteHost $logg.Info("DataStore Name: $datastoreName") $logg.Info("NFS_HOST_ARRAY: $nfsHost") $nfsPath = $datastore.RemotePath $datastore.ExtensionData.Host | %{ $mountingHostId = $_.Key.GetHashCode() Add-Content $nasShareFile ([byte[]][Char[]] "\N`t$mountingHostId`t$datastoreId`t$nfsHost`t$nfsPath`t$capacityMB`n") -Encoding Byte } } } }