So i initially tried getting this to loop through all the folders but couldn't figure it out so i made it so i could pass the folder as a parameter but ideally i want it to do all VMs without having to enter any parameters. Any ideas on how to best do this? I want to make csv files for each folder with all the custom attributes for each VM contained within.
##Variables
Param($Param1)
$report = @()
$folders = get-folder $Param1 # | sort name
############################################################################################
###########################
ForEach ($folder in $folders)
{
$vms = get-vm -location $folder
ForEach ($vm in $vms)
{
$ReportObj = "" | Select "Folder", "Virtual Machine", "POC", "Username", "Password",
$ReportObj."Folder" = $folder.name
$ReportObj."Virtual Machine" = $vm.name
$ReportObj."POC" = $vm.CustomFields
$ReportObj."Username" = $vm.CustomFields
$ReportObj."Password" = $vm.CustomFields
$Report += $ReportObj
$csvfile = "D:\"$folder".csv"
$report | Export-CSV $csvfile -NoTypeInformation
}
}