windows:scripts:powershell:remove_vmwaretools
Различия
Показаны различия между двумя версиями страницы.
| Следующая версия | Предыдущая версия | ||
| windows:scripts:powershell:remove_vmwaretools [2026/02/27 10:35] – создано | windows:scripts:powershell:remove_vmwaretools [2026/02/27 10:41] (текущий) – | ||
|---|---|---|---|
| Строка 1: | Строка 1: | ||
| ====== Remove VMwareTools ====== | ====== Remove VMwareTools ====== | ||
| **Удаление VMwareTools.**\\ | **Удаление VMwareTools.**\\ | ||
| + | Если образ был создан на виртуальной машине то перед клонированием можно удалить все элементы относящиеся к VMwareTools.\\ | ||
| + | ===== Запуск ===== | ||
| + | **[[..: | ||
| + | |||
| + | ===== Код ===== | ||
| + | <code powershell Remove_VMwareTools.ps1> | ||
| + | # This script will manually rip out all VMware Tools registry entries and files for Windows 2008-2019 | ||
| + | # Tested for 2019, 2016, and probably works on 2012 R2 after the 2016 fixes. | ||
| + | |||
| + | # This function pulls out the common ID used for most of the VMware registry entries along with the ID | ||
| + | # associated with the MSI for VMware Tools. | ||
| + | function Get-VMwareToolsInstallerID { | ||
| + | foreach ($item in $(Get-ChildItem Registry:: | ||
| + | If ($item.GetValue(' | ||
| + | return @{ | ||
| + | reg_id = $item.PSChildName; | ||
| + | msi_id = [Regex]:: | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | $vmware_tools_ids = Get-VMwareToolsInstallerID | ||
| + | |||
| + | # Targets we can hit with the common registry ID from $vmware_tools_ids.reg_id | ||
| + | $reg_targets = @( | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | ) | ||
| + | |||
| + | $VMware_Tools_Directory = " | ||
| + | $VMware_Common_Directory = " | ||
| + | |||
| + | # Create an empty array to hold all the uninstallation targets and compose the entries into the target array | ||
| + | $targets = @() | ||
| + | |||
| + | If ($vmware_tools_ids) { | ||
| + | foreach ($item in $reg_targets) { | ||
| + | $targets += $item + $vmware_tools_ids.reg_id | ||
| + | } | ||
| + | # Add the MSI installer ID regkey | ||
| + | $targets += " | ||
| + | } | ||
| + | |||
| + | # This is a bit of a shotgun approach, but if we are at a version less than 2016, add the Uninstaller entries we don't | ||
| + | # try to automatically determine. | ||
| + | If ([Environment]:: | ||
| + | $targets += " | ||
| + | $targets += " | ||
| + | $targets += " | ||
| + | } | ||
| + | |||
| + | # Add the VMware, Inc regkey | ||
| + | If (Test-Path " | ||
| + | $targets += " | ||
| + | } | ||
| + | |||
| + | # Add the VMware Tools directory | ||
| + | If(Test-Path $VMware_Tools_Directory) { | ||
| + | $targets += $VMware_Tools_Directory | ||
| + | } | ||
| + | |||
| + | # Thanks to @Gadgetgeek2000 for pointing out that the script leaves some 500mb of extra artifacts on disk. | ||
| + | # This blob removes those. | ||
| + | If(Test-Path $VMware_Common_Directory) { | ||
| + | $targets += $VMware_Common_Directory | ||
| + | } | ||
| + | |||
| + | # Create a list of services to stop and remove | ||
| + | $services = Get-Service -DisplayName " | ||
| + | $services += Get-Service -DisplayName " | ||
| + | |||
| + | # Warn the user about what is about to happen | ||
| + | # Takes only y for an answer, bails otherwise. | ||
| + | Write-Host "The following registry keys, filesystem folders, and services will be deleted:" | ||
| + | If (!$targets -and !$services ) { | ||
| + | Write-Host " | ||
| + | } | ||
| + | Else { | ||
| + | $targets | ||
| + | $services | ||
| + | $user_confirmed = Read-Host " | ||
| + | If ($user_confirmed -eq " | ||
| + | |||
| + | # Stop all running VMware Services | ||
| + | $services | Stop-Service -Confirm: | ||
| + | |||
| + | # Cover for Remove-Service not existing in PowerShell versions < 6.0 | ||
| + | If (Get-Command Remove-Service -errorAction SilentlyContinue) { | ||
| + | $services | Remove-Service -Confirm: | ||
| + | } | ||
| + | Else { | ||
| + | foreach ($s in $services) { | ||
| + | sc.exe DELETE $($s.Name) | ||
| + | } | ||
| + | } | ||
| + | |||
| + | # Remove all the files that are listed in $targets | ||
| + | foreach ($item in $targets) { | ||
| + | If(Test-Path $item) { | ||
| + | Remove-Item -Path $item -Recurse | ||
| + | } | ||
| + | } | ||
| + | Write-Host "Done. Reboot to complete removal." | ||
| + | } | ||
| + | Else { | ||
| + | Write-Host " | ||
| + | } | ||
| + | } | ||
| + | |||
| + | </ | ||
windows/scripts/powershell/remove_vmwaretools.1772177750.txt.gz · Последнее изменение: —
