VMware Cloud Community
NiceAdmin
Contributor
Contributor

Get current time for all VM of the host or the cluster without authentication

Hello,

i want with powerCLi , obtain by host or by cluster the date-time and the VM name associate for each VM without authentication because each VM has its own password 

invoke-VMscript command given date-time but  we have to go through an identification, and the output don't give the name of the VM

It is possible

Thank you for your help

0 Kudos
3 Replies
LucD
Leadership
Leadership

Without authentication this will be difficult, if not impossible, through Invoke-VMScript.
If your VMs are running Windows and are part of a domain and they have the VMware Tools installed, you could use the Get-WmiObject cmdlet.

Get-VM |

Select Name,@{N='DateTime';E={

    $obj = Get-WmiObject -ComputerName $_.Guest.HostName -Class Win32_operatingsystem

    $obj.ConvertToDateTime($obj.LocalDateTime)}}

For VMs that have another guest OS, or are missing any of the requirements above, it will be difficult to get their local date and time


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
NiceAdmin
Contributor
Contributor

thank you for your answer, it confirms what I understood, like it's not easy with the only command that can do it, except put the same password to all VM linux and VM windows server
0 Kudos
LucD
Leadership
Leadership

Not necessarily.
I store multiple user/password combinations in the CredentialStore, then I try them one-by-one.

Note that I use the Host part of the credentialstoreitem as a lable, i.e. win1,win2,lin1...

$foundCreds = $false

foreach($cred in Get-VICredentialStoreItem){

    if(-not $foundCreds){

        Try{

            $result = Invoke-VMScript -VM $vm -ScriptText $winCode -ScriptType Bat -GuestUser $cred.User -GuestPassword $cred.Password -ErrorAction Stop

            $foundCreds = $true

            $correctCreds = $cred

        }

        Catch [VMware.VimAutomation.ViCore.Types.V1.ErrorHandling.InvalidGuestLogin] {

            $obj.GuestCreds = 'nok'

            $obj.InvokeScript = 'ok'

        }

        Catch{

            $obj.InvokeScript = 'nok'

        }

    }

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos