I'm getting some strange data in my CSV report when I add an If Else Statement to @properties snippet to store data. Green highlighted block is where I'm having issue (I've commented it). I just want to add 1 or 0 to the report if VM is replicating or not.
$Report = @()
$vms = Get-VM
Foreach ($vm in $vms){
$VMTier = $vm | get-SpbmEntityConfiguration | Where-Object {($_.StoragePolicy -like '*Tier*')}
$VMReplicated = Get-SrmProtectedVM -Name $vm -PeerState Shadowing
$Properties = @{
VM = $vm
StoragePolicy = $VMTier.StoragePolicy
Replicated = $VMReplicated.PeerState
}
# If ($VMReplicated.PeerState -eq 'Shadowing') {
# $Properties = @{
# VM = $vm
# StoragePolicy = $VMTier.StoragePolicy
# Replicated = 1}
# Else {
# $Properties = @{
# VM = $vm
# StoragePolicy = $VMTier.StoragePolicy
# Replicated = 0}
# }
# }
Remove-Variable VMTier, VMReplicated -Force -ErrorAction SilentlyContinue
$Report += New-Object psobject -Property $properties
}
$Report | select VM,@{Name="Storage Policy"; Expression={$_.StoragePolicy}},Replicated | Export-Csv $Filename -notypeinformation
Thanks, SK
A moderator should be along to move your thread to the PowerCLI area.
What do you mean by "strange data"?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
output file is showing datastore names.
Did you try with $VMTier.StoragePolicy.Name?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference