I created the below script and I'm not able to find a way to get the User logged in, could you please assist me
Function ConnectTo-vCenter
{
$connection = Get-Credential -Message “Please enter your Login & password”
foreach ($vCenter in $vCenterList)
{
Connect-VIServer $vCenter -Credential $connection -Port 443
Fonc_LOG "Connecting to $vCenter..."
if ($? -eq $true) {
Fonc_LOG "Successfully connected to $vCenter"
}
else {
Fonc_LOG "Not Connected to $vCenter Please Check your Credential)"
}
}
}
ConnectTo-vCenter
Try something like this (it should work on Windows but also on Linux and MacOS).
You could add [Environment]::UserDomain, but that probably does not return anything on Linux and MacOS stations.
Fonc-LOG "Script started by $([Environment]::UserName) on $([Environment]::MachineName)"
$connection = Get-Credential -Message “Please enter your Login & password”
foreach ($vCenter in $vCenterList) {
Connect-VIServer $vCenter -Credential $connection -Port 443
Fonc_LOG "Connecting to $vCenter..."
if ($? -eq $true) {
Fonc_LOG "Successfully connected to $vCenter"
else {
Fonc_LOG "Not Connected to $vCenter Please Check your Credential)"
}
}
}
}
ConnectTo-vCenter
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference