azaac
(azaac)
1
Hey guys,
Trying to formulate a script to check a VM for a config variable and then acting apon that depending on the result.
I have the results pulling from a text file of machines.
So far a snippet I have a problem with is below:
foreach ($vm in $vms) {
$binfo = Get-VM | Select {$_.ExtensionData.Config.Firmware}
if ($binfo -contains ‘efi’){
Write-host “EFI Found”
} else {
Write-Host “Using Bios mode”
}
}
The Issue I have is the if/else statement does not work correctly, I get the same result if there is or isn’t efi contained in the result.
Anyone able to shed some better light on this for me?
1 Spice up
Neally
(Neally)
2
If you post code, please use the insert code button. Please and thank you.

michaelsc
(Michael.SC)
3
foreach ($vm in $vms) {
$binfo = Get-VM | Select
{$_.ExtensionData.Config.Firmware}
if ($binfo -contains 'efi'){
Write-host "EFI Found"
} else {
Write-Host "Using Bios mode"
}
}
Cleaned it up a little. What are you pulling the data from and what data are you getting without filters?
dreid007
(Don007)
4
You’re getting information for all VMs with Get-VM. You need to pass $vm to it: Get-VM $vm | …
azaac
(azaac)
5
I’m using
$Inputfile = vm.txt
$vms = get-content -path $Inputfile
The vm.txt contains a list of vm names.
My purpose of the script is;
A script was run on the machines changing the bios to EFI.
Machines that have been rebooted obviously wont boot the operating system up.
I need to search the vm’s running config for if its set to bios to remove the advancedsetting for EFI.
azaac
(azaac)
6
Sorry, forgot to mention this is VM’s on VMware not hyper-v
Neally
(Neally)
7
AFAIK changing from BIOS to EFI is a peculiar process.
Does the Generation change as well if you update from BIOS to EFI? I have never done it, just read about it.
Is there anything else you can go of?
Your select statement does not seem to do much, for me anyways, In have BIOS and EFI machines, but no converted one.
Neally
(Neally)
8
Herp derp… that makes a HUGE difference haha
Agree with Don007’s comment above, pretty sure that’s your problem.
jitensh
(JitenSh)
10
import-module hyperv
$GetVM = Get-VM -ComputerName HyperV
Foreach ($vm in $GetVM)
{
get-vm $vm
}
You can try something like
Evan7191
(Evan7191)
11
Try -match instead of -contains. -match uses regular expressions to match strings. You can use multiple -match and -notmatch statements together. For example, If ($VM -match ‘efi’ -AND $VM -notmatch ‘UEFI’)
Neally
(Neally)
12
Alrighty we have vmware at work, i got rid of all vmware stuff at home 
Try like so:
get-content 'C:\import.txt'|
foreach{
Get-VM $_ | Select @{name='Firmware';e={$_.ExtensionData.Config.Firmware}} |
foreach{
if($_.firmware -like "*efi*"){
Write-Output "VM '$($_.name)' is using EFI"
}else{
Write-Output "VM '$($_.name)' is using BIOS"
}
}
}