skhan22
Contributor
Contributor

PowerCLI Script - Create Report from Two Cmdlets with If Statement

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

0 Kudos
4 Replies
scott28tt
VMware Employee
VMware Employee

 A moderator should be along to move your thread to the PowerCLI area.


-------------------------------------------------------------------------------------------------------------------------------------------------------------

Although I am a VMware employee I contribute to VMware Communities voluntarily (ie. not in any official capacity)
VMware Training & Certification blog
0 Kudos
LucD
Leadership
Leadership

What do you mean by "strange data"?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
skhan22
Contributor
Contributor

output file is showing datastore names.

0 Kudos
LucD
Leadership
Leadership

Did you try with $VMTier.StoragePolicy.Name?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos