Jump to content

Recommended Posts

Posted

Hi,

I am struggling to try to run powercli to get the count of desktops for each Horizon pool. I am receiving the attached error. What am I doing wrong? 

Import-Module VMware.VimAutomation.Core
Import-Module -Name VMware.VimAutomation.HorizonView
Import-Module VMware.Hv.Helper
Import-Module ImportExcel

$server = "myserver"

# Specify the output Excel file path
$outputExcelFile = "C:\Horizon_Desktop_Counts.xlsx"

$adminUser = "" 
$adminPassword = Read-Host -Prompt "Enter password for $adminUser" -AsSecureString

Connect-HVServer -Server $server

$pools = Get-HVPool
$poolData = @()

foreach ($pool in $pools) {
     $poolName = $pool.Name  

    $desktops = Get-HVMachine -PoolName $poolName -ErrorAction SilentlyContinue
    if ($desktops) {
        $desktopCount = $desktops.Count
    } else {
        $desktopCount = 0
    }

     $poolData += [PSCustomObject]@{
        PoolName      = $poolName
        DesktopCount  = $desktopCount
    }
}


if ($poolData.Count -gt 0) {
    $poolData | Export-Excel -Path $outputExcelFile -AutoSize -Title "Desktop Counts Per Pool"
    Write-Host "Data has been exported to $outputExcelFile."
} else {
    Write-Host "No pool data retrieved. Excel file will not be created."
}

Disconnect-HVServer -Confirm:$false

horizon.png

Posted

@Wouter Kursten,

I have followed the instructions and this is what I receive with the module folder in each location. Each of the folders are copied to all the PowerShell module locations

image.png.58aee930bfb3b96006e1908b16326c48.png

image.png.0e572e1bdb6e7bb6f1455ce64c560768.png

 

image.png.4323295029e64ad9eb6f66376f004d26.png

Posted

Still getting the same issue if you have any thoughts. I am trying to get a count of each workstation in a pool. 

# Ensure required modules are loaded
# Ensure required modules are loaded
Import-module Omnissa.VimAutomation.HorizonView
Import-module -name Omnissa.Hv.Helper
Import-Module ImportExcel


# Specify the Horizon Connection Server
$server = ""

# Specify the output Excel file path
$outputExcelFile = "C:\Horizon_Desktop_Counts.xlsx"

# Prompt for admin credentials
$adminUser = "y" # Replace with your admin username
$adminPassword = Read-Host -Prompt "Enter password for $adminUser" -AsSecureString

# Connect to VMware Horizon
Connect-HVServer -Server $server

# Retrieve pool information
$pools = Get-HVPool
$poolData = @()

foreach ($pool in $pools) {
    # Adjust field name based on actual structure
    $poolName = $pool.Name  # Use .Name if .Id doesn't work

    # Retrieve desktops, handling potential failures
    $desktops = Get-HVMachine -PoolName $poolName -ErrorAction SilentlyContinue
    if ($desktops) {
        $desktopCount = $desktops.Count
    } else {
        $desktopCount = 0
    }

    # Add data to the array
    $poolData += [PSCustomObject]@{
        PoolName      = $poolName
        DesktopCount  = $desktopCount
    }
}

# Export data to an Excel file only if there's data
if ($poolData.Count -gt 0) {
    $poolData | Export-Excel -Path $outputExcelFile -AutoSize -Title "Desktop Counts Per Pool"
    Write-Host "Data has been exported to $outputExcelFile."
} else {
    Write-Host "No pool data retrieved. Excel file will not be created."
}

# Disconnect from VMware Horizon
Disconnect-HVServer -Confirm:$false

image.png.de1beb20f5436b6225c268e8e57e0f51.png

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...