Nu-UDChartJS not populating

Product: PowerShell Universal
Version: 1.4.6

Good evening everyone,

I’m trying to create a charge of free disk space for each server in a specific OU. It creates a charter for each server but does not populate the charts with the bars. I have 11 servers in the OU, it creates 11 charts which is what I want, they’re just empty. Thanks

Code:

    $serverList = (Get-ADComputer -Filter * -SearchBase "OU=Servers,OU=Computers,DC=local" | Select-Object -ExpandProperty Name)
    foreach ($server in $serverList) {
        $GraphPrep = @(
            Disk = $server; TotalDiskSpace = ((Get-CimInstance -ComputerName $server -ClassName Win32_LogicalDisk -Filter "DeviceID='C:'").Size / 1GB | ForEach-Object { "$([Math]::Round($_, 2)) GBs " }); FreeDiskSpace = ((Get-CimInstance -ComputerName $server -ClassName Win32_LogicalDisk -Filter "DeviceID='C:'").FreeSpace / 1GB | ForEach-Object { "$([Math]::Round($_, 2)) GBs " })
        )            
        $availableDiskSpace = New-UDChartJSDataset -DataProperty "TotalDiskSpace" -Label 'Total' -BackgroundColor blue
        $freeDiskSpace = New-UDChartJSDataset -DataProperty "FreeDiskSpace" -Label 'Free' -BackgroundColor red

        $Options = @{
            Type          = 'bar'
            Data          = $GraphPrep
            Dataset       = @($availableDiskSpace, $freeDiskSpace)
            LabelProperty = "Disk"
            Options = @{
                scales = @{
                    xAxes = @(
                    @{
                        stacked = $true
                    }
                )
                yAxes = @(
                    @{
                        stacked = $true
                    }
                )
                }
            }
        } 
        New-UDChartJS @Options
    }

You can’t include the GBs text in the value because then it won’t be a number. Try this instead.

foreach ($server in @("localhost")) {
        $GraphPrep = @{
            Disk = $server; TotalDiskSpace = ((Get-CimInstance -ComputerName $server -ClassName Win32_LogicalDisk -Filter "DeviceID='C:'").Size / 1GB); FreeDiskSpace = ((Get-CimInstance -ComputerName $server -ClassName Win32_LogicalDisk -Filter "DeviceID='C:'").FreeSpace / 1GB)
        }            
        $availableDiskSpace = New-UDChartJSDataset -DataProperty "TotalDiskSpace" -Label 'Total (GBs)' -BackgroundColor blue
        $freeDiskSpace = New-UDChartJSDataset -DataProperty "FreeDiskSpace" -Label 'Free (GBs)' -BackgroundColor red

        $Options = @{
            Type          = 'bar'
            Data          = $GraphPrep
            Dataset       = @($availableDiskSpace, $freeDiskSpace)
            LabelProperty = "Disk"
            Options = @{
                scales = @{
                    xAxes = @(
                    @{
                        stacked = $true
                    }
                )
                yAxes = @(
                    @{
                        stacked = $true
                    }
                )
                }
            }
        } 
        New-UDChartJS @Options
    }

That does seem to do the trick. Now I see that this only captures the C: drive. What if there are multiple drives per server? How would I make a bar for each drive? I’m going to try and figure it out myself but any help would be appreciated.

Thank you!

I figured it out. Thank you!