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.
There is not code that I can see.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Are you sure the script works?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
i didnt try yet.
Any help here ?
Did you try the script in the meantime?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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.
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.
You mean like this?
I'm not sure why you only select the last event.
$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
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.
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
PS C:\Users\rsahu_a\Desktop> Get-Content -Path .\vmnames.txt
PTL24AT
alt22cso
Ok, does this return the VM objects?
Get-VM -Name $vmNames
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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
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
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.Count
$vmNames
Get-VM -Name $vmNames
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference