Hi,
The below powercli script prompts for user input. Not sure how to fix it. I do not want it to prompt for user output as I am runinng the code as part of bigger script. How do I make it silently run ? Any help would be greatly appreciate.
function VMHostDiskDetails {
$DateVar = get-date -uformat "%Y-%m-%d_%I.%M.%S.%p"
$VMHosts = Get-VMHost # Get all the VM-Hosts
$Datastores = $VMHosts | Get-Datastore # Get the Datastore info for all the VMHosts
$VMHostStorage = $VMHosts | ForEach-Object { #Then, for each VMHosts, get the VMHostName
$VMHost = $_.Name
$_ | Get-VMHostStorage | Select-Object -expandProperty FileSystemVolumeInfo | `
ForEach-Object {
$VMHostStorageName = $_.Name
Add-Member -InputObject $_ -MemberType NoteProperty -Name FreeSpaceMB -Value ($Datastores | Where-Object {$_.Name -eq $VMHostStorageName}).FreeSpaceMB -PassThru | `
Add-Member -MemberType NoteProperty -Name HostName -Value $VMHost -PassThru
Add-Member -MemberType NoteProperty -Name TimeStamp -Value $DateVar
}
}
$VMHostStorage | Select HostName,Name,AccessMode,Type,Capacity,FreeSpaceMB, Path, TimeStamp | Export-Csv VMHostStorage.csv -notype
}
VMHostDiskDetails
Thanks
M
The 2nd Add-Member line didn't put the object on the pipeline.
The 3th Add-Member line didn't have a -PassThru parameter.
function VMHostDiskDetails { $DateVar = get-date -uformat "%Y-%m-%d_%I.%M.%S.%p" $VMHosts = Get-VMHost mmmstv004* # Get all the VM-Hosts $Datastores = $VMHosts | Get-Datastore # Get the Datastore info for all the VMHosts $VMHostStorage = $VMHosts | ForEach-Object { #Then, for each VMHosts, get the VMHostName $VMHost = $_.Name $_ | Get-VMHostStorage | Select-Object -expandProperty FileSystemVolumeInfo | ` ForEach-Object { $VMHostStorageName = $_.Name Add-Member -InputObject $_ -MemberType NoteProperty -Name FreeSpaceMB -Value ($Datastores | Where-Object {$_.Name -eq $VMHostStorageName}).FreeSpaceMB -PassThru | ` Add-Member -MemberType NoteProperty -Name HostName -Value $VMHost -PassThru | ` Add-Member -MemberType NoteProperty -Name TimeStamp -Value $DateVar -PassThru } } $VMHostStorage | Select HostName,Name,AccessMode,Type,Capacity,FreeSpaceMB, Path, TimeStamp | Export-Csv VMHostStorage.csv -notype } VMHostDiskDetails
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The 2nd Add-Member line didn't put the object on the pipeline.
The 3th Add-Member line didn't have a -PassThru parameter.
function VMHostDiskDetails { $DateVar = get-date -uformat "%Y-%m-%d_%I.%M.%S.%p" $VMHosts = Get-VMHost mmmstv004* # Get all the VM-Hosts $Datastores = $VMHosts | Get-Datastore # Get the Datastore info for all the VMHosts $VMHostStorage = $VMHosts | ForEach-Object { #Then, for each VMHosts, get the VMHostName $VMHost = $_.Name $_ | Get-VMHostStorage | Select-Object -expandProperty FileSystemVolumeInfo | ` ForEach-Object { $VMHostStorageName = $_.Name Add-Member -InputObject $_ -MemberType NoteProperty -Name FreeSpaceMB -Value ($Datastores | Where-Object {$_.Name -eq $VMHostStorageName}).FreeSpaceMB -PassThru | ` Add-Member -MemberType NoteProperty -Name HostName -Value $VMHost -PassThru | ` Add-Member -MemberType NoteProperty -Name TimeStamp -Value $DateVar -PassThru } } $VMHostStorage | Select HostName,Name,AccessMode,Type,Capacity,FreeSpaceMB, Path, TimeStamp | Export-Csv VMHostStorage.csv -notype } VMHostDiskDetails
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LuCD. It worked.