I am writing a script in RHEL-powerCLI to fetch few VM information (last login user ).. I will be given login credentials of ESXI ONLY...(not Vms)
My first doubt is... : [ powerCLI running in VM named RHEL7.4-Amogh ]
[1] when I use -
" Get-VIEvent -MaxSamples 1"
I am able to get last login user...saying..
FullFormattedMessage : User root@192.168.**.** logged in as PowerCLI/1.0.0.********
[2] but in the powercli script for all VMs in esxi.. [ (vm) is name which I am passing ]
" Get-VM (vm) | Get-VIEvent -MaxSamples 1 "
I get last login time when Vm is powered ON...
FullFormattedMessage : RHEL7.4-Amogh on localhost.localdomain in ha-datacenter is powered on...
Why cant the output of [1] shown in output of [2]..
----------------------------------------------------------------------------------------------------------------------
My second doubt is...... :
We have ESXi in which there are 4 VMs poweredOn..
in that one VM I am using [I used ssh to login to VM ].. and other 3 are used by someone else.. [ they use 'ssh' to login or may be they use some other ways ]
when I try to see last login user and time with
forEach (VM - PoweredON ) { Get-VIEvent -Entity VM -MaxSample 1 }
I get to see only my VM's output but not other 3 VMs....
[ this is the error which I get
You cannot call a method on a null-valued expression.
At /root/amg_4_GetVMinfo.ps1:71 char:3
+ $LastLoginTime = $event.CreatedTime.ToString("dd/MM/yyy HH:MM:ss") ]
May I know why ?
Thank You