B
B
Berkutman2019-05-01 12:52:08
PowerShell
Berkutman, 2019-05-01 12:52:08

Powercli, Powershell VM authorization check?

Hello. there is a task. checking authorization in a virtual machine in vCenter ESXi
In vCenter ESXi, for example, there is a CLIENTM virtual machine, you need to check authorization on the machine, if the login and password are not correct, it gives an error, if it is correct, it displays that the authorization has passed.

Now I made a crutch like this

If (Invoke-VMScript -vm $CLIENTM -ScriptText "ipconfig" -GuestUser '[email protected]' -GuestPassword '[email protected]' -ScriptType Powershell)

   {Invoke-VMScript -vm $CLIENTM -ScriptText "echo LOGIN FOR IZHEVSk YES" -GuestUser '[email protected]' -GuestPassword '[email protected]' -ScriptType Powershell | Out-File D:\result.txt -Append -NoClobber}

ElseIf (Invoke-VMScript -vm $CLIENTM -ScriptText "ipconfig" -GuestUser '[email protected]' -GuestPassword '[email protected]' -ScriptType Powershell)

   {Invoke-VMScript -vm $CLIENTM -ScriptText "echo LOGIN FOR MOSCOW YES IZHEVSk NO" -GuestUser '[email protected]' -GuestPassword '[email protected]' -ScriptType Powershell | Out-File D:\result.txt -Append -NoClobber}

Else

   {Invoke-VMScript -vm $CLIENTM -ScriptText "echo LOGIN FOR IZHEVSk and MOSCOW NO" -GuestUser '[email protected]' -GuestPassword '[email protected]' -ScriptType Powershell | Out-File D:\result.txt -Append -NoClobber}


If (Invoke-VMScript -vm $CLIENTM -ScriptText "ipconfig" -GuestUser '[email protected]' -GuestPassword '[email protected]' -ScriptType Powershell)

   {Invoke-VMScript -vm $CLIENTM -ScriptText "echo LOGIN FOR MOSCOW YES" -GuestUser '[email protected]' -GuestPassword '[email protected]' -ScriptType Powershell | Out-File D:\result.txt -Append -NoClobber}

Else

   {Invoke-VMScript -vm $CLIENTM -ScriptText "echo LOGIN FOR IZHEVSk and MOSCOW NO" -GuestUser '[email protected]' -GuestPassword '[email protected]' -ScriptType Powershell | Out-File D:\result.txt -Append -NoClobber}


It works, but I would like to find the correct cmdlet.

Well, the conclusion depends on the fulfillment of the conditions.
ScriptOutput
-----------------------------------------------------------------------------------------------------------------------|  LOGIN
|  FOR
|  IZHEVSk
|  YES
|  
-----------------------------------------------------------------------------------------------------------------------



ScriptOutput
-----------------------------------------------------------------------------------------------------------------------|  LOGIN
|  FOR
|  MOSCOW
|  YES
|  
-----------------------------------------------------------------------------------------------------------------------

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question