VMware Cloud Community
riksyours
Contributor
Contributor

I want to get the replication status (Ok, Initial Syncing, Recovered, Recovering) for given no. of servers using powerCli

I want to get the replication status like (Ok, Initial Syncing, Recovered, Recovering) for given no. of servers using powerCli

I got the below code from internet but not tested because it will check entire Vcenter.

0 Kudos
16 Replies
LucD
Leadership
Leadership

There is not code that I can see.


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

0 Kudos
LucD
Leadership
Leadership

Are you sure the script works?


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

0 Kudos
riksyours
Contributor
Contributor

i didnt try yet.

0 Kudos
riksyours
Contributor
Contributor

Any help here ?

0 Kudos
LucD
Leadership
Leadership

Did you try the script in the meantime?


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

0 Kudos
riksyours
Contributor
Contributor

No i cant run this script in my env. as i am not much sure what all it will do. I have given link here for reference.

0 Kudos
riksyours
Contributor
Contributor

Hi LucD​,

I got your reply on one of question asked but someone else.

I want to get it similar like below for given multiple server.

$vmNames = (Get-Content -Path .\vmnames.txt) -join '|'

Get-VIEvent -MaxSamples ([int]::MaxValue) |

Where { $_.EventTypeId -match "hbr|rpo" } |

Select CreatedTime, FullFormattedMessage -last 1, @{Name="VMName";Expression={$_.Vm.Name}} |

export-csv -NoTypeInformation -Path ([Environment]::GetFolderPath("Desktop") + "\HBR-RPOEvents.csv")

Can you tell me whats wrong in this code. It is not giving expected result and concatenating.

0 Kudos
LucD
Leadership
Leadership

You mean like this?

I'm not sure why you only select the last event.

$vmNames = Get-Content -Path .\vmnames.txt

$vms = Get-VM -Name $vmNames


Get-VIEvent -Entity $vms -MaxSamples ([int]::MaxValue) |

Where-Object { $_.EventTypeId -match "hbr|rpo" } |

Select-Object -Last 1 -Property CreatedTime, FullFormattedMessage, @{Name="VMName";Expression={$_.Vm.Name}} |

Export-Csv -Path ([Environment]::GetFolderPath("Desktop") + "\HBR-RPOEvents.csv") -NoTypeInformation


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

0 Kudos
riksyours
Contributor
Contributor

Getting below error,

Get-VM : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then

try the command again.

At line:1 char:21

+ $vms = Get-VM -Name $vmNames

+                     ~~~~~~~~

    + CategoryInfo          : InvalidData: (:) [Get-VM], ParameterBindingValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

I am using "-last 1" to see only last (Latest) replication event for that server.

0 Kudos
LucD
Leadership
Leadership

That could mean that the file vmnames.txt does not contain any VM displaynames.

What does this return?

Get-Content -Path .\vmnames.txt


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

0 Kudos
riksyours
Contributor
Contributor

PS C:\Users\rsahu_a\Desktop> Get-Content -Path .\vmnames.txt

PTL24AT

alt22cso

0 Kudos
LucD
Leadership
Leadership

Ok, does this return the VM objects?

Get-VM -Name PTL24AT,alt22cso

And does this return the same?

$vmNames = Get-Content -Path .\vmnames.txt

Get-VM -Name $vmNames


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

0 Kudos
riksyours
Contributor
Contributor

PS C:\Users\rsahu_a\Desktop> $vms = Get-VM -Name PTL24AT,alt22cso

PS C:\Users\rsahu_a\Desktop> echo $vms

Name                 PowerState Num CPUs MemoryGB      

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

PTL24AT      PoweredOn  2        8.000         

alt22cso          PoweredOn  12       32.000

0 Kudos
riksyours
Contributor
Contributor

PS C:\Users\rsahu_a\Desktop> $vmnames = Get-Content -Path .\vmnames.txt

PS C:\Users\rsahu_a\Desktop> Get-VM -Name $vmNames

Get-VM : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then

try the command again.

At line:1 char:14

+ Get-VM -Name $vmNames

+              ~~~~~~~~

    + CategoryInfo          : InvalidData: (:) [Get-VM], ParameterBindingValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

0 Kudos
LucD
Leadership
Leadership

So the VMs are there, and you are connected.

It seems to be an issue with the Get-Content and/or the file.

Can you do the following?

$vmNames = Get-Content -Path .\vmnames.txt

$vmNames.Count

$vmNames

Get-VM -Name $vmNames


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

0 Kudos