Issue is Getting VCenter cluster details

Hi All,

i want to build a dashboard to get Vcenter and cluster details. i have used UDSelectOption options to manually populate VC details once i select VC in the dropdown it should show cluster details in another Dropdown. but while connection to VC i am getting this Error

Cannot validate argument on parameter 'Server'. The argument is null or empty. Provide an argument that is not null or empty

and then try the command again. Below is the code. when i try to connect via command line using Connect-VIServer -server its connecting but not when i use UD. Kindly help me to reslove this issue.

$HomePage = New-UDPage -Name "Home" -Icon home -Content { 
        New-UDRow -Columns {
            New-UDColumn -Size 6 -Content {
                New-UDSelect -Label "VCENTER List" -Option {
                    New-UDSelectOption -Name "vcname" -Value "vcname"
                    New-UDSelectOption -Name "vcname" -Value "vcname"
                    New-UDSelectOption -Name "vcname" -Value "vcname"
                    New-UDSelectOption -Name "vcname" -Value "vcname"
                } -OnChange {
                    $Session:Character = $EventData
                    Show-UDToast -Message "Changed to $($eventdata)" -Duration 5000
                    $Session:Server = ( [string]$eventdata ).Trim( '"' )
                    Sync-UDElement -Id "Clu"
                }
            }
        }
                 New-UdColumn -Size 4 -Endpoint {
                 $ESXiConnectionTest  = Connect-VIServer -server $($Session:Server) -Credential $Cache:cred
                        }

So without trying the code, I am assuming this toast displays the correct server name selected?

Also assuming that Connect-VIServer is a module, and you have correctly imported the module into UD so you can use it’s commands within UD?

Thank you

Hi PSDevUK,

yes, it was not properly imported because Powercli was not supported in Powershell core thanks for that. now i am getting new error.

The property 'ModuleBase' cannot be found on this object. Verify that the property exists.
Below is the Code i have used now i am using powershell version 5

> $HomePage = New-UDPage -Name "Home" -Icon home -Content { 
>         New-UDRow -Columns {
>             New-UDColumn -Size 6 -Content {
>                 New-UDSelect -Label "VCENTER List" -Option {
>                     New-UDSelectOption -Name "vcname" -Value "vcname"
>                     New-UDSelectOption -Name "vcname" -Value "vcname"
>                     New-UDSelectOption -Name "vcname" -Value "vcname"
>                     New-UDSelectOption -Name "vcname" -Value "vcname"
>                 } -OnChange {
>                     $Session:Character = $EventData
>                     Show-UDToast -Message "Changed to $($eventdata)" -Duration 5000
>                     $Session:Server = ( [string]$eventdata ).Trim( '"' )
>                     Sync-UDElement -Id "Clu"
>                 }
>             }
>         }
>                  New-UdColumn -Size 4 -Endpoint {
> Import-Module VMware.PowerCLI
>                  $ESXiConnectionTest  = Connect-VIServer -server $($Session:Server) -Credential $Cache:cred
>                         }

Only going by the new error, but are you using “ModuleBase” anywhere else in your dashboard?

No this was my complete code

New-UdColumn -Size 4 -Endpoint {
Import-Module VMware.PowerCLI
ESXiConnectionTest = Connect-VIServer -server "($Session:Server)" -Credential $Cache:cred
}
#
# foreach($cache:clusters in Get-Cluster ){}
}
#Create the dashboard
Start-UDDashboard -Content {
New-UDDashboard -NavbarLinks $NavBarLinks -Title “Dashboard - OS Deployment” -NavBarColor ‘#FF1c1c1c’ -NavBarFontColor “#FF55b3ff” -BackgroundColor “white” -FontColor “#FFFFFFF” -Pages @(
$HomePage
) -Footer $Footer
} -Port 1000 -Name ‘ContentDashboard’ -AutoReloa

i have fixed this by importing Powercli module correctly. But the issue is if i enter a VC it should pull all cluster details. its not getting the proper details.
if first time i put vcenter details and click submit it will not load the values when i refresh it will load the values in the drop down list. it should show the values when i put vcenter details and click submit button can any one help me on this

Get-UDDashboard -Name ‘ContentDashboard’ | Stop-UDDashboard
$Cache:pw = convertto-securestring -AsPlainText -Force -String ‘password’
$Cache:cred = new-object -typename System.Management.Automation.PSCredential -argumentlist “username”,$Cache:pw
$Link = New-UDLink -Text ‘Blog’ -Url ‘http://www.google
$Footer = New-UDFooter -Copyright ‘test’ -Links $Link
$NavBarLinks = @((New-UDLink -Text “About” -Url “http://google.com” -Icon question_circle),
(New-UDLink -Text “More info” -Url “http://www.google.com” -Icon book))

$HomePage = New-UDPage -Name “Home” -Icon home -Content {
New-UDRow -Columns {
New-UDColumn -Size 4 -Content {

         New-UDInput -Title "Enter VC" -SubmitText "Submit" -Endpoint {

         param([string]$Message)
         New-UDInputAction -Toast $Message
        $Cache:viserver= Connect-VIServer -Server "$Message" -Credential $Cache:cred
        $cache:clusters = Get-Cluster
        }
    New-UDColumn -Size 4 -Endpoint { 
         New-UDSelect -Label "VCENTER Cluster Details" -Option  {
           foreach($cache:cluster in $cache:clusters){
          
           New-UDSelectOption -Name "$cache:cluster" -Value "$cache:cluster"
        } 
      
        }
} 
         
    }
}
         
}       #      

#Create the dashboard
Start-UDDashboard -Content {
import-module VMware.PowerCLI
New-UDDashboard -NavbarLinks $NavBarLinks -Title “Dashboard - OS Deployment” -NavBarColor ‘#FF1c1c1c’ -NavBarFontColor “#FF55b3ff” -BackgroundColor “white” -FontColor “#FFFFFFF” -Pages @(
$HomePage
) -Footer $Footer
} -Port 1000 -Name ‘ContentDashboard’ -AutoReload