VMware Cloud Community
victorarok
Contributor
Contributor

3D Graphics" to disable

Hi All,

Please help me on below case

I want to list all the vms on which 3d graphic is enabled.If enabled I need to disable it without powering off the vm.

Thanks,

vic

Reply
0 Kudos
30 Replies
LucD
Leadership
Leadership

To find the VMs with 3D enabled, see Re: Get VMs with 3D enabled


To disable the 3D feature, can do the following.
But I'm not too sure that this can be do while the VM is powered on.

$vmName = 'MyVM'

$vm = Get-View -ViewType VirtualMachine -Filter @{'Name'="^$($vmName)$"}

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec

$dc = New-Object VMware.Vim.VirtualDeviceConfigSpec

$dc.Operation = 'edit'

$dev = $vm.Config.Hardware.Device | where{$_ -is [VMware.Vim.VirtualMachineVideoCard]}

$dev.enable3DSupport = $false

$dc.Device += $dev

$spec.DeviceChange += $dc

$vm.ReconfigVM($spec)


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

Reply
0 Kudos
victorarok
Contributor
Contributor

Hi LucD,

Thank you for response.

should we run this script by giving vm name each time .just thinking of this comment $vmName ='MyVM'

If we want to add all the vms which are 3d enabled in  a text file or excel .and ask the script to use this excel file to process on vms for disable.

Please advice how to add these parameters in scripts.

Thankyou,

Vic

Reply
0 Kudos
LucD
Leadership
Leadership

Did you already test if it works with a powered on VM?


You can combine both scripts into one.

Something like this

Get-View -ViewType VirtualMachine -Property Name,Config.Hardware.Device |

where{($_.Config.Hardware.Device | Where-Object {$_ -is [VMware.Vim.VirtualMachineVideoCard]}).Enable3DSupport} |

ForEach-Object {

    $spec = New-Object VMware.Vim.VirtualMachineConfigSpec

    $dc = New-Object VMware.Vim.VirtualDeviceConfigSpec

    $dc.Operation = 'edit'

    $dev = $vm.Config.Hardware.Device | where{$_ -is [VMware.Vim.VirtualMachineVideoCard]}

    $dev.enable3DSupport = $false

    $dc.Device += $dev

    $spec.DeviceChange += $dc

   

    $vm.ReconfigVM($spec)

}


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

Reply
0 Kudos
victorarok
Contributor
Contributor

No I did not test .I wanted to test this script on one vm.

How I can use this for just one vm?

Reply
0 Kudos
LucD
Leadership
Leadership

Add a Filter on the Get-View cmdlet in the 1st line

Get-View -ViewType VirtualMachine -Property Name,Config.Hardware.Device -Filter @{'Name'='MyVM'} |


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

Reply
0 Kudos
victorarok
Contributor
Contributor

Get-View : The term 'Get-View' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that

the path is correct and try again.

At C:\3dgrphic.ps1:2 char:1

+ Get-View -ViewType VirtualMachine -Property Name,Config.Hardware.Devi ...

+ ~~~~~~~~

    + CategoryInfo          : ObjectNotFound: (Get-View:String) [], CommandNotFoundException

    + FullyQualifiedErrorId : CommandNotFoundException

Reply
0 Kudos
LucD
Leadership
Leadership

Do any of the other PowerCLI cmdlets work for you?

Can you try cmdlets like Get-VM or Get-VMHost?
Also, can you check your PowerCLI version with

Get-Module -Name VMware* -ListAvailable

And check your PowerShell folders with

$env:PSModulePath.Split(';')


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

Reply
0 Kudos
victorarok
Contributor
Contributor

powercli verstion is 6.0 and  powershell folders

C:\Users\Documents\WindowsPowerShell\Modules

C:\Program Files\WindowsPowerShell\Modules

C:\Windows\system32\WindowsPowerShell\v1.0\Modules

C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Modules

Also get-vm & get-VMhost is showing proper output without any errors

Reply
0 Kudos
LucD
Leadership
Leadership

And what does the Get-Module line return?


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

Reply
0 Kudos
victorarok
Contributor
Contributor

ModuleType Version    Name                                ExportedCommands

---------- -------    ----                                ----------------

Binary     6.0.0.0    VMware.VimAutomation.Cis.Core

Binary     6.0.0.0    VMware.VimAutomation.Cloud

Manifest   6.0.0.0    VMware.VimAutomation.Core

Binary     6.0.0.0    VMware.VimAutomation.HA

Binary     1.0.0.0    VMware.VimAutomation.License

Binary     6.0.0.0    VMware.VimAutomation.PCloud

Manifest   6.0.0.0    VMware.VimAutomation.SDK

Binary     6.0.0.0    VMware.VimAutomation.Storage

Binary     6.0.0.0    VMware.VimAutomation.Vds

Binary     1.0.0.0    VMware.VimAutomation.vROps

Binary     6.0.0.0    VMware.VumAutomation

Reply
0 Kudos
victorarok
Contributor
Contributor

ModuleType VersionName                            ExportedCommands
---------- -----------                            ----------------
Script 0.0    Initialize-VMware.VimAutomation....
Script 0.0    Initialize-VMware.VimAutomation....
Script 0.0    Initialize-VMware_VimAutomation_Cis
Script 0.0    Initialize-VMware_VimAutomation_Vds
Script 0.0    Initialize-VMware_VumAutomation
Manifest   3.1.0.0Microsoft.PowerShell.Management {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Content...}
Manifest   3.1.0.0Microsoft.PowerShell.Utility    {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
Binary 6.0.0.0VMware.VimAutomation.Cis.Core   {Connect-CisServer, Disconnect-CisServer, Get-CisService}
Binary 6.0.0.0VMware.VimAutomation.Cloud      {Add-CIDatastore, Connect-CIServer, Disconnect-CIServer, Get-Catalog...}
Script 6.0.0.0VMware.VimAutomation.Core
Binary 6.0.0.0VMware.VimAutomation.HA         Get-DrmInfo
Binary 1.0.0.0VMware.VimAutomation.License    Get-LicenseDataManager
Binary 6.0.0.0VMware.VimAutomation.PCloud     {Connect-PIServer, Disconnect-PIServer, Get-PIComputeInstance, Get-PIDatacenter}
Manifest   6.0.0.0VMware.VimAutomation.Sdk
Binary 6.0.0.0VMware.VimAutomation.Storage    {Export-SpbmStoragePolicy, Get-NfsUser, Get-SpbmCapability, Get-SpbmCompatibleStorage...}
Binary 6.0.0.0VMware.VimAutomation.Vds        {Add-VDSwitchPhysicalNetworkAdapter, Add-VDSwitchVMHost, Export-VDPortGroup, Export-VDSwitch...}
Binary 1.0.0.0VMware.VimAutomation.vROps      {Connect-OMServer, Disconnect-OMServer, Get-OMAlert, Get-OMAlertDefinition...}
Binary 6.0.0.0VMware.VumAutomation            {Add-EntityBaseline, Copy-Patch, Get-Baseline, Get-Compliance...}

PowerCLI C:\>

Reply
0 Kudos
LucD
Leadership
Leadership

Looks like not all modules and PSSnapin are loading/loaded.

You should seriously consider upgrading to a more recent version.

See Welcome PowerCLI to the PowerShell Gallery – Install Process Updates


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

Reply
0 Kudos
victorarok
Contributor
Contributor

I tried with updateing all the modules.but it ended up with this error.Please help me if its have any alertnet for vmware.vim

Could not load file or assembly 'VMware.Vim, Version=6.7.0.1516, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

At C:\3dgrphic.ps1:1 char:1

+ $vm = get-view -ViewType VirtualMachine -Property Name,Config.Hardwar ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : OperationStopped: (:) [], FileNotFoundException

    + FullyQualifiedErrorId : System.IO.FileNotFoundException

Reply
0 Kudos
LucD
Leadership
Leadership

Did you follow the uninstall procedure in the blog post I linked to earlier?
You will first have to uninstall the MSI package, and then make sure there is nothing left, before doing the Install-Module.


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

Reply
0 Kudos
victorarok
Contributor
Contributor

After all trobleshooting module worked properly.The script executed successfully however it did show any successful message  and also it did not change the configuration  status of 3D.I think vm need reboot

Thankyou LucD

Reply
0 Kudos
victorarok
Contributor
Contributor

Is it possible to take backup of vmx file and just modify the vmx file  from  "mks.enable3d=TRUE", to "mks.enable3d=False", and reload the vmx file through script

Reply
0 Kudos
LucD
Leadership
Leadership

You can download the VMX file to your station, change the content and then upload it again.

See for example Re: how can modify/change key in VMX file


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

Reply
0 Kudos
victorarok
Contributor
Contributor

Can I use this below script.But iam not sure if this (Get-Content $oldvmx | where {$_ -notmatch "mks.enable3d=False"} | Set-Content $newvmx) is trying to modify existing parameter("mks.enable3d=TRUE",).Please advice

$vm = Get-VM -Name MyVM

$datastorename,$filepath = $vm.ExtensionData.Config.Files.VmPathName.split(" ")

$datastorename = $datastorename.TrimStart("[").TrimEnd("]")

$filename = $filepath.Split('/')[-1]

$oldvmx = $env:temp + "\" + $filename

$newvmx = $env:temp + "\new" + (Get-Random -Maximum 1GB) + ".vmx"

$ds = Get-Datastore -Name $datastorename

Remove-VM -VM $vm -Confirm:$false

New-PSDrive -Name ds -PSProvider VimDatastore -Root '/' -Location $ds Copy-DatastoreItem -Item "ds:\$($filepath)" -Destination $oldvmx

Get-Content $oldvmx | where {$_ -notmatch "mks.enable3d=False"} | Set-Content $newvmx

Copy-DatastoreItem -Item $newvmx -Destination "ds:\$($filepath)" -Force -Confirm:$false

Remove-PSDrive -Name ds

New-VM -VMFilePath $vm.ExtensionData.Config.Files.VmPathName -VMHost $vm.Host -Confirm:$false

Reply
0 Kudos
LucD
Leadership
Leadership

No, that is removing the line with "mks.enable3d=False" from the VMX file.

And I'm pretty sure the VM needs to be powered off for this.

Btw, it seems some formatting in the original thread want wrong.

The corrected script

$vm = Get-VM -Name MyVM

$datastorename,$filepath = $vm.ExtensionData.Config.Files.VmPathName.split(" ")

$datastorename = $datastorename.TrimStart("[").TrimEnd("]")

$filename = $filepath.Split('/')[-1]

$oldvmx = $env:temp + "\" + $filename

$newvmx = $env:temp + "\new" + (Get-Random -Maximum 1GB) + ".vmx"

$ds = Get-Datastore -Name $datastorename

Remove-VM -VM $vm -Confirm:$false

New-PSDrive -Name ds -PSProvider VimDatastore -Root '/' -Location $ds

Copy-DatastoreItem -Item "ds:\$($filepath)" -Destination $oldvmx

Get-Content $oldvmx | where {$_ -notmatch "mks.enable3d=False"} | Set-Content $newvmx

Copy-DatastoreItem -Item $newvmx -Destination "ds:\$($filepath)" -Force -Confirm:$false

Remove-PSDrive -Name ds

New-VM -VMFilePath $vm.ExtensionData.Config.Files.VmPathName -VMHost $vm.Host -Confirm:$false


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

Reply
0 Kudos