bansne's Posts

but i am initializing it  $connectedVMCsv = New-Object System.Collections.ArrayList $migrationCsv = New-Object System.Collections.ArrayList  or i missed something  
@fannol  thanks for the reply but it would work if vm in vlan but in broken state, it will only show one which are healthy
Hi @LucD , Hope you are doing well. I need small help from you . I am trying to get list of vm's inside specific vlan but for some reason csv shows repetetive output.For exapmle on console output i... See more...
Hi @LucD , Hope you are doing well. I need small help from you . I am trying to get list of vm's inside specific vlan but for some reason csv shows repetetive output.For exapmle on console output i see vlan 123 got vmabc but in csv i get same entry for vmabc twice/thrice.   Following is my code i am trying to run. All i am after is list of vms (even if not connected to n/w but part of vlan123) in the csv output just once.   $VCServer = "vc123","vc235","vc987" $ReportExport = "/tmp/" $vcUser = "admin" $vcPass = "xxxx" $VLANs = "1234","5678","0986" $connectedVMCsvPath = "/tmp/list.csv" $migrationCsvPath = "/tmp/$($migrationgroup).csv" # Get the Migration Group (change#) from the environment variable $migrationgroup = "Group9"   # Initialize an empty array to store all results $allResults = New-Object System.Collections.Generic.List[PSCustomObject] #$allResults = New-Object System.Collections.ArrayList   # Define the CSV headers for connected VMs $connectedVMHeader = "vCenter Server,VM Name,VM IP Address,PowerState,PortGroup" $connectedVMCsv = New-Object System.Collections.ArrayList   # Define the CSV headers for migration list $migrationHeader = "VM_Name,MIGRATION_GROUP" $migrationCsv = New-Object System.Collections.ArrayList     function Get-VMsForVLAN {     param (         [string]$VCServer,         [string]$VLAN     )       if ($?) {         Write-Host "Connected to $VCServer"           $portGroups = Get-VDPortgroup | Where-Object { $_.Name -like "*$VLAN*" }             foreach ($port in $portGroups) {             Write-Host "Found VLAN $($port); Proceeding with checking of VMs" -foreground green               $networks = Get-View -ViewType Network -Property Name -Filter @{"Name" = $($port.name)}             $networks | ForEach-Object {                 ($_.UpdateViewData("Vm.Name", "Vm.Runtime.PowerState", "Vm.Guest.IPAddress"))             }               foreach ($network in $networks) {                 $vms = $network.LinkedView.Vm                   if ($vms) {                     foreach ($vm in $vms) {                         $vmName = $vm.Name                         $existingEntry = $results | Where-Object { $_.'VM Name' -eq $vmName -and $_.'VLAN Name' -eq $vlan }                           if ($existingEntry) {                             # VM entry already exists for this VM and VLAN, skip adding it                             continue                         }                           $connectedVMRow = [PSCustomObject]@{                             'vCenter Server' = $VCServer                             'VLAN Name'      = $vlan                             'VM Name'        = $vmName                             'VM IP Address'  = ($vm.Guest.IPAddress | Where-Object { $_ -match '^10\.' }) -join ", "                             'PowerState'     = $vm.Runtime.PowerState                             'PortGroup'      = $network.Name                         }                         $null = $connectedVMCsv.Add($connectedVMRow)                           # Print VM information when found                         Write-Host "VM Name: $($connectedVMRow.'VM Name'), Power State: $($connectedVMRow.PowerState), IP Address: $($connectedVMRow.'VM IP Address')" -foreground cyan                         $migrationRow = [PSCustomObject]@{                             'VM_Name'         = $vm.Name                             'MIGRATION_GROUP' = $MIGRATIONGROUP                         }                         $null = $migrationCsv.Add($migrationRow)                     }                 }             }         }         # Do not disconnect here         return $results     }     else {         Write-Warning "Error connecting to vCenter Server $VCServer"         return $null     } }   function Get-UniqueVMs {     param (         [array]$results     )       $uniqueVMs = @{}       foreach ($result in $results) {         $vmName = $result.VMName           if ($uniqueVMs.ContainsKey($vmName)) {             $uniqueVM = $uniqueVMs[$vmName]             $uniqueVM.PortGroup += ", " + $result.PortGroup         }         else {             $uniqueVMs[$vmName] = $result         }     }       return $uniqueVMs.Values }   foreach ($server in $VCServer) {     Connect-VIServer -Server $server -User $vcUser -Password $vcPass -ErrorAction SilentlyContinue     if ($?) {         Write-Host "Connected to $server"     }     else {         Write-Warning "Error connecting to vCenter Server $server"         continue     }       foreach ($vlan in $VLANs) {         Write-Host "Running for VLAN: $vlan on vCenter Server: $server"           $vmResults = Get-VMsForVLAN -VCServer $server -VLAN $vlan         $uniqueVMResults = Get-UniqueVMs -results $vmResults             # Add unique VM entries to the results     foreach ($uniqueVMResult in $uniqueVMResults) {     $null = $allResults.Add($uniqueVMResult)  # Adding to $allResults only once     }   }       # Convert ArrayList to arrays before exporting to CSV     $connectedVMArray = $connectedVMCsv.ToArray()     $migrationArray = $migrationCsv.ToArray()         # Output the CSV data for connected VMs     if ($connectedVMArray.Count -gt 0) { Write-Host "Exporting connected VMs to CSV..."         $connectedVMArray | Export-Csv -Path $connectedVMCsvPath -NoTypeInformation -Append     }     else {         Write-Output "No virtual machines found on vCenter: $server"     }       # Output the CSV data for migration list     if ($migrationArray.Count -gt 0) {         $migrationArray | Export-Csv -Path $migrationCsvPath -NoTypeInformation -Append     }     else {         Write-Output "No virtual machines found on vCenter: $server"     }       # Disconnect from vCenter Server at the end of processing all VLANs      Write-Host "##[warning] Disconnecting from vCenterServer: $server" -ForegroundColor Red      Disconnect-VIServer -Server $server -Confirm:$false Start-Sleep -Seconds 10 }      
Exactly but only one additional thing i need report  for specific vms only in vc   Get-VM -Name $VM | Get-View maybe?
Is there a way to ignore name of vm in end from output of path please only <dc>\<parent>\<child>\  currently i am getting  <dc>\<parent>\<child>\<VM name> @LucD 
thanks for all your help. Worked like charm. Not sure after services.sh ideally it should disconnect and reconnect host but didn't do it this time. Wonder if it is actually restarting service.... See more...
thanks for all your help. Worked like charm. Not sure after services.sh ideally it should disconnect and reconnect host but didn't do it this time. Wonder if it is actually restarting service.
awsome , let me run this and get back to you Thanks alot
Hi, It worked , getting output like below , and setting is disabled on cluster true true true true true true true true true is there way to give details like hostname and on w... See more...
Hi, It worked , getting output like below , and setting is disabled on cluster true true true true true true true true true is there way to give details like hostname and on which host its true and on which it was not applicable. lastly is there single liner to restart services.sh on all host. after above is done.
sure let me give this a try... Regards
Hi, Is there a way to disable system swap setting on each esxi in vCenter Server. i can do one by one using Esxi-->Configure-->System swap. But how to do for all in cluster. i can on... See more...
Hi, Is there a way to disable system swap setting on each esxi in vCenter Server. i can do one by one using Esxi-->Configure-->System swap. But how to do for all in cluster. i can only see option to find where it is active. foreach($esx in Get-VMHost){   $esxcli = Get-EsxCli -VMHost $esx   $esxcli.sched.swap.system.get() | Select @{N='VMHost';E={$esx.Name}},HostLocalSwapActive } not much of use.
Could see its there in version 8.0 , how I want it. Thanks for all your replies.
Thanks for your reply. Always been of great help.  LucD​
Hi, The script works i am getting values less than100 and =0 . However , what if i want all values greater than 50% or equal to 100%. What i want is to check if my  /tmp directory is full o... See more...
Hi, The script works i am getting values less than100 and =0 . However , what if i want all values greater than 50% or equal to 100%. What i want is to check if my  /tmp directory is full or about to be full. I got alert on one esxi "The ramdisk 'root' is full. As a result, the file /testfile could not be written." need to validate other hosts stats in vc. Regards
I am using vROPS version 6.5. What if gives stats if I want to move vm etc. But If I am taking vms out of one cluster and moving to another cluster in same VC. How much capacity we would need.... See more...
I am using vROPS version 6.5. What if gives stats if I want to move vm etc. But If I am taking vms out of one cluster and moving to another cluster in same VC. How much capacity we would need.
the issue was space . Changed the name of folder and managed to get script working.
Hi, I found out this thread Free INODES and % free RAMDISK  with exactly what I was looking for. However, I want export that will list details of only ESXi with more than 50% memory been used... See more...
Hi, I found out this thread Free INODES and % free RAMDISK  with exactly what I was looking for. However, I want export that will list details of only ESXi with more than 50% memory been used under /tmp directory. eq to 100 or maybe greater than 50%. foreach($esxi in (Get-VMHost)){     $esxcli = Get-EsxCli -vmhost $esxi     $details +=(         $esxcli.system.visorfs.get() |          if ($details | where {$_.'Ramdisk Name' -eq "tmp"}) -eq 100){ write-output $esxi.name} }       LucD​ Regards
Hi, I have requirement to migrate VMs off from one cluster to another in same VC. However , i need to share plan how many ESXI i would need to make sure i am able to accomodate all VMs in new ... See more...
Hi, I have requirement to migrate VMs off from one cluster to another in same VC. However , i need to share plan how many ESXI i would need to make sure i am able to accomodate all VMs in new cluster. I Checked in vROPS it is giving option how much space i would need if i have to move VM etc. How and where can i check capacity needed to move VMs off one cluster to another. Is there anyway i can do it from VROPS?
Hi, Few things to check 1) storage is shared across clusters from and too? 2) network/vlan is accessible over two clusters? 3) EVC will not work if you got different hardware in two cluste... See more...
Hi, Few things to check 1) storage is shared across clusters from and too? 2) network/vlan is accessible over two clusters? 3) EVC will not work if you got different hardware in two clusters , you enabled evc with intel etc/? what we have in other cluster host? This all pre-requites is to live migrate VM 4) What is the error you see when you say migration is failing? can you paste full error. Try tail -f /var/log/vpxd.log  while you initiate migration to see cause of failure. Regards
Hi, Yes "VM and Template" type folder.
Hi, No it does not work. It did say Move into resource pool(Target is name of my cluster) but not to folder in vc datacenter. I tried after renaming folder name and it works using old scrip... See more...
Hi, No it does not work. It did say Move into resource pool(Target is name of my cluster) but not to folder in vc datacenter. I tried after renaming folder name and it works using old script. Is it anyway possible if i can poweroff and then delete existing ova and create new on the above script too? Regards Neha Bansal