VMware Cloud Community
kkikki130
Contributor
Contributor

vshield Endpoint driver check via PowerCLI for specific VM only.

Hello,

I gave thankful reply as below link before.

Re: Powercli script > how to show output if login fail!

I have a one more question.

The below main script is only for all of the VM.

If the target VMs were 500, and login fail VMs were 200!.

I need to run the script for 200 login fail VMs.

is it possible to run the script for specific VM?

for example, target vm list is in textfile(notepad) then run the script from the text file.. is it possible?

I hope to understand, but I am not good at English..

Thank you.

FYI, below is main script!

$vms=GET-VM |  Where-Object {$_.PowerState -eq "PoweredOn" }

 

ForEach($vm in $vms)

 

   if (Get-VMguest -VM $vm | Where-Object {$_.OSFullName -like "*Microsoft*"})

 

   try{

   $out = Invoke-VMScript -VM $vm -GuestUser "administrator" -GuestPassword "vmware1!" `

   -ScriptText "sc query type= driver | find `"vsepflt`" " -ScriptType bat -ErrorAction Stop |

   Select -ExpandProperty ScriptOutput

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

   $out = "Invalid logon"

   catch{

   $out = "Other error"

   Write-Output "VM: $($vm.Name): $out"

0 Kudos
2 Replies
kkikki130
Contributor
Contributor

I did it.

This is script for my question.

$vms = Import-Csv "D:\vmlist4.csv"

ForEach($vm in $vms)

 

   if (Get-VMguest -VM $($vm.vmname))

 

   try{

   $out = Invoke-VMScript -VM $($vm.vmname) -GuestUser "administrator" -GuestPassword "vmware1!" `

   -ScriptText "sc query type= driver | find `"vsepflt`" " -ScriptType bat -ErrorAction Stop |

   Select -ExpandProperty ScriptOutput

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

   $out = "Invalid logon"

   catch{

   $out = "Other error"

   Write-Output "VM: $($vm.vmname): $out"

Just create "vmlist4.csv" as below.

vmname

vCenter

VM1

VM2

...

Thanks a lot!

0 Kudos
dmmcsherry
Enthusiast
Enthusiast

To run against just a single VM, all you need to do is modify the first line:

$vms = Get-VM -Name "VMNAMEHERE"

0 Kudos