Created
August 11, 2016 21:15
-
-
Save rogfut/ad8072cd2740276d500761e5970a3072 to your computer and use it in GitHub Desktop.
stomplee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import csv | |
$csv = Import-CSV -Name c:\myfile.csv | |
#define empty array | |
$arr = @() | |
foreach($row in $csv) { | |
#create an object to store the data for the specific vm you are targeting | |
$obj = New-Object -TypeName PSObject | |
#get the datastore info | |
$datastore = Get-VM $row.vm | Get-Datastore | |
#add values from the datastore info to the object | |
$obj | Add-Member -Name 'vmname' -MemberType Noteproperty -Value $datastore.vmname | |
$obj | Add-Member -Name 'datastorename' -MemberType Noteproperty -Value $datastore.datastorename | |
$obj | Add-Member -Name 'datastorecapacity' -MemberType Noteproperty -Value $datastore.datastorecapacity | |
$obj | Add-Member -Name 'datastorefreespace' -MemberType Noteproperty -Value $datastore.datastorefreespace | |
#add the object to the array | |
$arr += $obj | |
} | |
#output the contents of the array | |
$arr | |
$arr | ConvertTo-CSV | Export-CSV -Path C;\output.csv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment