VMware Cloud Community
SCharchouf
Hot Shot
Hot Shot

Get-Logged User

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 Smiley Happy

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

0 Kudos
1 Reply
LucD
Leadership
Leadership

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.

Function ConnectTo-vCenter {

    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

0 Kudos