I create the below function in order to connect to vCenter, unfortunately when I run it nothing happen
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]$Server,
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]$Username,
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[SecureString]$Password
)
try {
# Import the VMware PowerCLI module
Import-Module -Name VMware.PowerCLI -ErrorAction Stop
# Connect to vCenter
Connect-VIServer -Server $Server -User $Username -Password $Password
# Output success message
Write-Output "Connected to vCenter successfully"
}
catch {
# Log the error
Write-Error "Failed to connect to vCenter: $_"
}
}