[{"data":1,"prerenderedAt":1834},["ShallowReactive",2],{"post:\u002F2013\u002F10\u002F25\u002Fpowershell-download-vmx-file-rename-upload-add-to-inventory\u002F":3},{"post":4,"newer":1793,"older":1804,"related":1812,"series":1832},{"id":5,"title":6,"body":7,"canonical":1771,"categories":1772,"date":1775,"description":1776,"extension":1777,"featured":1778,"hero":1779,"image":1779,"meta":1780,"navigation":483,"path":1781,"readingTime":243,"seo":1782,"series":1779,"seriesOrder":1779,"sites":1783,"source":1785,"stem":1786,"tags":1787,"updated":1790,"url":1791,"__hash__":1792},"blog\u002Fblog\u002F2013\u002F10\u002F25\u002Fpowershell-download-vmx-file-rename-upload-add-to-inventory.md","PowerShell: Download VMX File, Rename, Upload, Add to Inventory",{"type":8,"value":9,"toc":1764},"minimark",[10,14,19,54,58,114,117,223,227,230,273,277,1716,1720,1760],[11,12,13],"p",{},"I was tasked with migrating a VMware 4.1 to 5.1 environment. This created a slight issue due to the fact that environment ran vShield. For those of you not familiar, vShield on 4.1 had 2 additional lines in the VMX file that was manually added. These VFILE lines caused the VM not to boot if it was moved to an environment where vShield 1.0 was not present. So to resolve this a script was needed to download all these VMs, remove the lines, then reupload the file with a different name. Well, here you go.",[15,16,18],"h2",{"id":17},"requirements","Requirements",[20,21,22,26,38,41,48,51],"ul",{},[23,24,25],"li",{},"PowerShell 2.0 or later.",[23,27,28,29,33,34,37],{},"VMware vSphere PowerCLI 5.x, loaded as the ",[30,31,32],"code",{},"VMware.VimAutomation.Core"," snap-in (the script calls ",[30,35,36],{},"Add-PSSnapin",").",[23,39,40],{},"Network access from the machine running the script to both the vCenter 4.1 and vCenter 5.1 servers.",[23,42,43,44,47],{},"Permission to browse and upload files on the datastores, and to register (",[30,45,46],{},"New-VM",") virtual machines in vCenter 5.1.",[23,49,50],{},"The datastores holding the VMs must be visible to the vCenter 5.1 server and to the ESX host you import to.",[23,52,53],{},"The two local working folders and the import folder in vCenter 5.1 must already exist (see the values to edit below).",[15,55,57],{"id":56},"parameters","Parameters",[59,60,61,80],"table",{},[62,63,64],"thead",{},[65,66,67,71,74,77],"tr",{},[68,69,70],"th",{},"Name",[68,72,73],{},"Type",[68,75,76],{},"Required",[68,78,79],{},"Description",[81,82,83,100],"tbody",{},[65,84,85,91,94,97],{},[86,87,88],"td",{},[30,89,90],{},"vcServer4",[86,92,93],{},"string",[86,95,96],{},"Yes",[86,98,99],{},"The vCenter 4.1 server to connect to.",[65,101,102,107,109,111],{},[86,103,104],{},[30,105,106],{},"vcServer5",[86,108,93],{},[86,110,96],{},[86,112,113],{},"The vCenter 5.1 server to connect to.",[11,115,116],{},"The script exits with a message if either server is missing. Edit these variables near the top of the script before running it:",[59,118,119,131],{},[62,120,121],{},[65,122,123,126,129],{},[68,124,125],{},"Variable",[68,127,128],{},"Value in the script",[68,130,79],{},[81,132,133,148,163,178,193,208],{},[65,134,135,140,145],{},[86,136,137],{},[30,138,139],{},"$outvmxdir",[86,141,142],{},[30,143,144],{},"C:\\scripts\\vmxfiles",[86,146,147],{},"Local folder that receives the downloaded VMX files. Must exist.",[65,149,150,155,160],{},[86,151,152],{},[30,153,154],{},"$outvmxnewdir",[86,156,157],{},[30,158,159],{},"C:\\scripts\\vmxfiles-new",[86,161,162],{},"Local folder for the modified VMX files. Must exist.",[65,164,165,170,175],{},[86,166,167],{},[30,168,169],{},"$vCluster",[86,171,172],{},[30,173,174],{},"NA Cluster",[86,176,177],{},"Cluster in vCenter 4.1 whose powered-on VMs are processed.",[65,179,180,185,190],{},[86,181,182],{},[30,183,184],{},"$VMFolderName",[86,186,187],{},[30,188,189],{},"Import",[86,191,192],{},"VM folder in vCenter 5.1 the VMs are imported into. Must exist.",[65,194,195,200,205],{},[86,196,197],{},[30,198,199],{},"$ESXHost",[86,201,202],{},[30,203,204],{},"\u003Cesx-host>",[86,206,207],{},"ESX host in vCenter 5.1 the VMs are imported to.",[65,209,210,215,220],{},[86,211,212],{},[30,213,214],{},"$ResPool",[86,216,217],{},[30,218,219],{},"Infrastructure",[86,221,222],{},"Resource pool in vCenter 5.1 the VMs are imported into.",[15,224,226],{"id":225},"usage","Usage",[11,228,229],{},"Pass the vCenter 4.1 server first and the vCenter 5.1 server second.",[231,232,237],"pre",{"className":233,"code":234,"language":235,"meta":236,"style":236},"language-powershell shiki shiki-themes github-light",".\\VM-GatherVMX.ps1 -vcServer4 \"\u003Cvcenter-4-server>\" -vcServer5 \"\u003Cvcenter-5-server>\"\n","powershell","",[30,238,239],{"__ignoreMap":236},[240,241,244,248,252,255,257,260,264,267,270],"span",{"class":242,"line":243},"line",1,[240,245,247],{"class":246},"sgsFI",".\\VM",[240,249,251],{"class":250},"sD7c4","-",[240,253,254],{"class":246},"GatherVMX.ps1 ",[240,256,251],{"class":250},[240,258,259],{"class":246},"vcServer4 ",[240,261,263],{"class":262},"sYBdl","\"\u003Cvcenter-4-server>\"",[240,265,266],{"class":250}," -",[240,268,269],{"class":246},"vcServer5 ",[240,271,272],{"class":262},"\"\u003Cvcenter-5-server>\"\n",[15,274,276],{"id":275},"script","Script",[231,278,280],{"className":233,"code":279,"language":235,"meta":236,"style":236},"\u003C#\n.SYNOPSIS\n    Downloads, updates and uploads VMX files with PowerCLI, then adds the VMs to the vCenter 5.1 inventory.\n.DESCRIPTION\n    Downloads the VMX file of every \"PoweredOn\" VM in the vCenter 4.1 cluster,\n    removes the vShield VFILE lines, and uploads the result to the same\n    datastore folder under a new name (\u003Cname>-51.vmx). Once uploaded, each VM is\n    imported into the new vCenter 5.1 server.\n.PARAMETER vcServer4\n    The vCenter 4.1 server to connect to.\n.PARAMETER vcServer5\n    The vCenter 5.1 server to connect to.\n.EXAMPLE\n    .\\VM-GatherVMX.ps1 -vcServer4 \"\u003Cvcenter-4-server>\" -vcServer5 \"\u003Cvcenter-5-server>\"\n.NOTES\n    Author  : Thomas Lasswell (https:\u002F\u002Fwww.techcolumnist.com)\n    Version : 1.1 (2026-09-20)\n    Requires: VMware vSphere PowerCLI 5.x (VMware.VimAutomation.Core snap-in)\n    History : 1.0 2013-10-25 Initial version.\n              1.1 2026-09-20 Fixed VM folder lookup (now after connecting to vCenter 5.1)\n                  and a variable clash that overwrote it, VMX names that contain\n                  \".\", \"v\", \"m\" or \"x\", and the unassigned $VMFullPath output.\n#>\nparam(\n    [string]$vcServer4,\n    [string]$vcServer5\n)\n\nClear-Host\n\nif (!$vcServer4) {\n    Write-Host \"No vCenter 4 Server Specified\"\n    exit\n}\nif (!$vcServer5) {\n    Write-Host \"No vCenter 5 Server Specified\"\n    exit\n}\n\n# Load PowerCLI.\nAdd-PSSnapin VMware.VimAutomation.Core\n$host.ui.rawui.WindowTitle = \"PowerShell [PowerCLI Snap-in Loaded]\"\n\n# Download VMX file location.\n$outvmxdir = \"C:\\scripts\\vmxfiles\"\n# Modified VMX file location.\n$outvmxnewdir = \"C:\\scripts\\vmxfiles-new\"\n# Cluster name in vCenter 4.1 to gather PoweredOn VMs.\n$vCluster = \"NA Cluster\"\n# VM folder name in vCenter 5.1. This folder needs to exist.\n$VMFolderName = \"Import\"\n# ESX host in vCenter 5.1 to import VM.\n$ESXHost = \"\u003Cesx-host>\"\n# Resource pool in vCenter 5.1 to import VM.\n$ResPool = \"Infrastructure\"\n\n# Connect to vCenter 4.1 server.\nConnect-VIServer $vcServer4\n\n$aVM = Get-VM -Location $vCluster | Where-Object { $_.PowerState -eq \"PoweredOn\" } | Select-Object Name, PowerState\n$aVMInfo = @()\nforeach ($vm in $aVM) {\n    $vname = $vm.name\n    Write-Host $vname\n\n    # Process VMX information.\n    $VMView = Get-VM $vname | Get-View\n    $VMPathName = $VMView.Config.Files.VmPathName\n    Write-Host $VMPathName\n\n    # Download VMX file.\n    $dsname = $VMPathName.Split(\" \")[0].TrimStart(\"[\").TrimEnd(\"]\")\n    $vmRelativePath = $VMPathName.Split(']')[1].TrimStart(' ')\n    Remove-PSDrive -Name fromds -ErrorAction SilentlyContinue\n    New-PSDrive -Name fromds -Location (Get-Datastore $dsname) -PSProvider VimDatastore -Root '\u002F' | Out-Null\n    $dlvmx = $outvmxdir + (\"\u002F\") + $vmRelativePath.Split('\u002F')[1]\n    $checkforoutfile = Test-Path $dlvmx\n    if ($checkforoutfile) {\n        Remove-Item $dlvmx\n    }\n    Copy-DatastoreItem -Item fromds:\\$vmRelativePath -Destination $outvmxdir -Force\n\n    # Update VMX file to -51 file without vShield lines.\n    $vmxfile = $VMPathName.Split(\"\u002F\")[1]\n    $vmxsource = $outvmxdir + \"\\\" + $vmxfile\n    $vmxdest = $outvmxnewdir + \"\\\" + [System.IO.Path]::GetFileNameWithoutExtension($vmxfile) + \"-51.vmx\"\n    $checkforoutfile = Test-Path $vmxdest\n    if ($checkforoutfile) {\n        Remove-Item $vmxdest\n    }\n    Get-Content $vmxsource | Where-Object { $_ -notmatch 'VFILE.globaloptions' -and $_ -notmatch 'scsi0:0.filters = \"VFILE\"' } | Set-Content $vmxdest\n    Add-Content $vmxdest \"`n#Modified to remove VFILE Lines\"\n\n    # Upload new VMX file to datastore.\n    Write-Host $vmxdest\n    $vmxupload = ($vmRelativePath -replace '\\.vmx$', '') + \"-51.vmx\"\n    Write-Host $vmxupload\n    Copy-DatastoreItem -Item $vmxdest -Destination fromds:\\$vmxupload -Force\n\n    # Set array for addition of VMs.\n    $obj = New-Object PSObject\n    $obj | Add-Member -MemberType NoteProperty -Name \"VMName\" -Value $vname\n    $obj | Add-Member -MemberType NoteProperty -Name \"VMDatastore\" -Value $dsname\n    $obj | Add-Member -MemberType NoteProperty -Name \"VMPathName\" -Value $vmxupload\n    $aVMInfo += $obj\n}\n\nRemove-PSDrive -Name fromds -ErrorAction SilentlyContinue\nDisconnect-VIServer $vcServer4 -Force -Confirm:$false\nStart-Sleep 5\n\n# Connect to vCenter 5.1 server.\nConnect-VIServer $vcServer5\n$VMFolder = Get-Folder $VMFolderName\n\n# Import VM to vCenter 5.1.\nforeach ($vm in $aVMInfo) {\n    $vname = $vm.VMName\n    $datastore = $vm.VMDatastore\n    $VMPath = $vm.VMPathName\n    Write-Host $vname\n    Write-Host $datastore\n    Write-Host $VMPath\n    $VMFullPath = \"[\" + $datastore + \"] \" + $VMPath\n    Write-Host $VMFullPath\n    New-VM -VMFilePath $VMFullPath -VMHost $ESXHost -Location $VMFolder -ResourcePool $ResPool | Out-Null\n}\n\nDisconnect-VIServer $vcServer5 -Force -Confirm:$false\n",[30,281,282,288,298,304,312,318,324,330,336,347,353,363,369,377,383,391,397,403,409,415,421,427,433,439,448,462,472,478,485,491,496,511,520,526,532,544,552,557,562,567,573,581,596,601,607,618,624,635,641,652,658,669,675,686,692,703,708,714,723,728,782,796,811,822,830,835,841,859,870,878,883,889,923,948,964,1004,1040,1054,1063,1071,1077,1098,1103,1109,1127,1148,1179,1191,1198,1205,1210,1253,1271,1276,1282,1289,1317,1325,1344,1349,1355,1369,1397,1422,1447,1459,1464,1469,1483,1505,1514,1519,1525,1533,1547,1552,1558,1570,1580,1591,1602,1609,1617,1625,1650,1658,1688,1693,1698],{"__ignoreMap":236},[240,283,284],{"class":242,"line":243},[240,285,287],{"class":286},"sAwPA","\u003C#\n",[240,289,291,295],{"class":242,"line":290},2,[240,292,294],{"class":293},"sYu0t",".",[240,296,297],{"class":250},"SYNOPSIS\n",[240,299,301],{"class":242,"line":300},3,[240,302,303],{"class":286},"    Downloads, updates and uploads VMX files with PowerCLI, then adds the VMs to the vCenter 5.1 inventory.\n",[240,305,307,309],{"class":242,"line":306},4,[240,308,294],{"class":293},[240,310,311],{"class":250},"DESCRIPTION\n",[240,313,315],{"class":242,"line":314},5,[240,316,317],{"class":286},"    Downloads the VMX file of every \"PoweredOn\" VM in the vCenter 4.1 cluster,\n",[240,319,321],{"class":242,"line":320},6,[240,322,323],{"class":286},"    removes the vShield VFILE lines, and uploads the result to the same\n",[240,325,327],{"class":242,"line":326},7,[240,328,329],{"class":286},"    datastore folder under a new name (\u003Cname>-51.vmx). Once uploaded, each VM is\n",[240,331,333],{"class":242,"line":332},8,[240,334,335],{"class":286},"    imported into the new vCenter 5.1 server.\n",[240,337,339,341,344],{"class":242,"line":338},9,[240,340,294],{"class":293},[240,342,343],{"class":250},"PARAMETER",[240,345,346],{"class":250}," vcServer4\n",[240,348,350],{"class":242,"line":349},10,[240,351,352],{"class":286},"    The vCenter 4.1 server to connect to.\n",[240,354,356,358,360],{"class":242,"line":355},11,[240,357,294],{"class":293},[240,359,343],{"class":250},[240,361,362],{"class":250}," vcServer5\n",[240,364,366],{"class":242,"line":365},12,[240,367,368],{"class":286},"    The vCenter 5.1 server to connect to.\n",[240,370,372,374],{"class":242,"line":371},13,[240,373,294],{"class":293},[240,375,376],{"class":250},"EXAMPLE\n",[240,378,380],{"class":242,"line":379},14,[240,381,382],{"class":286},"    .\\VM-GatherVMX.ps1 -vcServer4 \"\u003Cvcenter-4-server>\" -vcServer5 \"\u003Cvcenter-5-server>\"\n",[240,384,386,388],{"class":242,"line":385},15,[240,387,294],{"class":293},[240,389,390],{"class":250},"NOTES\n",[240,392,394],{"class":242,"line":393},16,[240,395,396],{"class":286},"    Author  : Thomas Lasswell (https:\u002F\u002Fwww.techcolumnist.com)\n",[240,398,400],{"class":242,"line":399},17,[240,401,402],{"class":286},"    Version : 1.1 (2026-09-20)\n",[240,404,406],{"class":242,"line":405},18,[240,407,408],{"class":286},"    Requires: VMware vSphere PowerCLI 5.x (VMware.VimAutomation.Core snap-in)\n",[240,410,412],{"class":242,"line":411},19,[240,413,414],{"class":286},"    History : 1.0 2013-10-25 Initial version.\n",[240,416,418],{"class":242,"line":417},20,[240,419,420],{"class":286},"              1.1 2026-09-20 Fixed VM folder lookup (now after connecting to vCenter 5.1)\n",[240,422,424],{"class":242,"line":423},21,[240,425,426],{"class":286},"                  and a variable clash that overwrote it, VMX names that contain\n",[240,428,430],{"class":242,"line":429},22,[240,431,432],{"class":286},"                  \".\", \"v\", \"m\" or \"x\", and the unassigned $VMFullPath output.\n",[240,434,436],{"class":242,"line":435},23,[240,437,438],{"class":286},"#>\n",[240,440,442,445],{"class":242,"line":441},24,[240,443,444],{"class":250},"param",[240,446,447],{"class":246},"(\n",[240,449,451,454,456,459],{"class":242,"line":450},25,[240,452,453],{"class":246},"    [",[240,455,93],{"class":250},[240,457,458],{"class":246},"]$vcServer4",[240,460,461],{"class":250},",\n",[240,463,465,467,469],{"class":242,"line":464},26,[240,466,453],{"class":246},[240,468,93],{"class":250},[240,470,471],{"class":246},"]$vcServer5\n",[240,473,475],{"class":242,"line":474},27,[240,476,477],{"class":246},")\n",[240,479,481],{"class":242,"line":480},28,[240,482,484],{"emptyLinePlaceholder":483},true,"\n",[240,486,488],{"class":242,"line":487},29,[240,489,490],{"class":293},"Clear-Host\n",[240,492,494],{"class":242,"line":493},30,[240,495,484],{"emptyLinePlaceholder":483},[240,497,499,502,505,508],{"class":242,"line":498},31,[240,500,501],{"class":250},"if",[240,503,504],{"class":246}," (",[240,506,507],{"class":250},"!",[240,509,510],{"class":246},"$vcServer4) {\n",[240,512,514,517],{"class":242,"line":513},32,[240,515,516],{"class":293},"    Write-Host",[240,518,519],{"class":262}," \"No vCenter 4 Server Specified\"\n",[240,521,523],{"class":242,"line":522},33,[240,524,525],{"class":250},"    exit\n",[240,527,529],{"class":242,"line":528},34,[240,530,531],{"class":246},"}\n",[240,533,535,537,539,541],{"class":242,"line":534},35,[240,536,501],{"class":250},[240,538,504],{"class":246},[240,540,507],{"class":250},[240,542,543],{"class":246},"$vcServer5) {\n",[240,545,547,549],{"class":242,"line":546},36,[240,548,516],{"class":293},[240,550,551],{"class":262}," \"No vCenter 5 Server Specified\"\n",[240,553,555],{"class":242,"line":554},37,[240,556,525],{"class":250},[240,558,560],{"class":242,"line":559},38,[240,561,531],{"class":246},[240,563,565],{"class":242,"line":564},39,[240,566,484],{"emptyLinePlaceholder":483},[240,568,570],{"class":242,"line":569},40,[240,571,572],{"class":286},"# Load PowerCLI.\n",[240,574,576,578],{"class":242,"line":575},41,[240,577,36],{"class":293},[240,579,580],{"class":246}," VMware.VimAutomation.Core\n",[240,582,584,587,590,593],{"class":242,"line":583},42,[240,585,586],{"class":293},"$host",[240,588,589],{"class":246},".ui.rawui.WindowTitle ",[240,591,592],{"class":250},"=",[240,594,595],{"class":262}," \"PowerShell [PowerCLI Snap-in Loaded]\"\n",[240,597,599],{"class":242,"line":598},43,[240,600,484],{"emptyLinePlaceholder":483},[240,602,604],{"class":242,"line":603},44,[240,605,606],{"class":286},"# Download VMX file location.\n",[240,608,610,613,615],{"class":242,"line":609},45,[240,611,612],{"class":246},"$outvmxdir ",[240,614,592],{"class":250},[240,616,617],{"class":262}," \"C:\\scripts\\vmxfiles\"\n",[240,619,621],{"class":242,"line":620},46,[240,622,623],{"class":286},"# Modified VMX file location.\n",[240,625,627,630,632],{"class":242,"line":626},47,[240,628,629],{"class":246},"$outvmxnewdir ",[240,631,592],{"class":250},[240,633,634],{"class":262}," \"C:\\scripts\\vmxfiles-new\"\n",[240,636,638],{"class":242,"line":637},48,[240,639,640],{"class":286},"# Cluster name in vCenter 4.1 to gather PoweredOn VMs.\n",[240,642,644,647,649],{"class":242,"line":643},49,[240,645,646],{"class":246},"$vCluster ",[240,648,592],{"class":250},[240,650,651],{"class":262}," \"NA Cluster\"\n",[240,653,655],{"class":242,"line":654},50,[240,656,657],{"class":286},"# VM folder name in vCenter 5.1. This folder needs to exist.\n",[240,659,661,664,666],{"class":242,"line":660},51,[240,662,663],{"class":246},"$VMFolderName ",[240,665,592],{"class":250},[240,667,668],{"class":262}," \"Import\"\n",[240,670,672],{"class":242,"line":671},52,[240,673,674],{"class":286},"# ESX host in vCenter 5.1 to import VM.\n",[240,676,678,681,683],{"class":242,"line":677},53,[240,679,680],{"class":246},"$ESXHost ",[240,682,592],{"class":250},[240,684,685],{"class":262}," \"\u003Cesx-host>\"\n",[240,687,689],{"class":242,"line":688},54,[240,690,691],{"class":286},"# Resource pool in vCenter 5.1 to import VM.\n",[240,693,695,698,700],{"class":242,"line":694},55,[240,696,697],{"class":246},"$ResPool ",[240,699,592],{"class":250},[240,701,702],{"class":262}," \"Infrastructure\"\n",[240,704,706],{"class":242,"line":705},56,[240,707,484],{"emptyLinePlaceholder":483},[240,709,711],{"class":242,"line":710},57,[240,712,713],{"class":286},"# Connect to vCenter 4.1 server.\n",[240,715,717,720],{"class":242,"line":716},58,[240,718,719],{"class":293},"Connect-VIServer",[240,721,722],{"class":246}," $vcServer4\n",[240,724,726],{"class":242,"line":725},59,[240,727,484],{"emptyLinePlaceholder":483},[240,729,731,734,736,739,741,744,747,750,753,756,759,762,765,768,770,773,776,779],{"class":242,"line":730},60,[240,732,733],{"class":246},"$aVM ",[240,735,592],{"class":250},[240,737,738],{"class":293}," Get-VM",[240,740,266],{"class":250},[240,742,743],{"class":246},"Location $vCluster ",[240,745,746],{"class":250},"|",[240,748,749],{"class":293}," Where-Object",[240,751,752],{"class":246}," { ",[240,754,755],{"class":293},"$_",[240,757,758],{"class":246},".PowerState ",[240,760,761],{"class":250},"-eq",[240,763,764],{"class":262}," \"PoweredOn\"",[240,766,767],{"class":246}," } ",[240,769,746],{"class":250},[240,771,772],{"class":293}," Select-Object",[240,774,775],{"class":246}," Name",[240,777,778],{"class":250},",",[240,780,781],{"class":246}," PowerState\n",[240,783,785,788,790,793],{"class":242,"line":784},61,[240,786,787],{"class":246},"$aVMInfo ",[240,789,592],{"class":250},[240,791,792],{"class":250}," @",[240,794,795],{"class":246},"()\n",[240,797,799,802,805,808],{"class":242,"line":798},62,[240,800,801],{"class":250},"foreach",[240,803,804],{"class":246}," ($vm ",[240,806,807],{"class":250},"in",[240,809,810],{"class":246}," $aVM) {\n",[240,812,814,817,819],{"class":242,"line":813},63,[240,815,816],{"class":246},"    $vname ",[240,818,592],{"class":250},[240,820,821],{"class":246}," $vm.name\n",[240,823,825,827],{"class":242,"line":824},64,[240,826,516],{"class":293},[240,828,829],{"class":246}," $vname\n",[240,831,833],{"class":242,"line":832},65,[240,834,484],{"emptyLinePlaceholder":483},[240,836,838],{"class":242,"line":837},66,[240,839,840],{"class":286},"    # Process VMX information.\n",[240,842,844,847,849,851,854,856],{"class":242,"line":843},67,[240,845,846],{"class":246},"    $VMView ",[240,848,592],{"class":250},[240,850,738],{"class":293},[240,852,853],{"class":246}," $vname ",[240,855,746],{"class":250},[240,857,858],{"class":293}," Get-View\n",[240,860,862,865,867],{"class":242,"line":861},68,[240,863,864],{"class":246},"    $VMPathName ",[240,866,592],{"class":250},[240,868,869],{"class":246}," $VMView.Config.Files.VmPathName\n",[240,871,873,875],{"class":242,"line":872},69,[240,874,516],{"class":293},[240,876,877],{"class":246}," $VMPathName\n",[240,879,881],{"class":242,"line":880},70,[240,882,484],{"emptyLinePlaceholder":483},[240,884,886],{"class":242,"line":885},71,[240,887,888],{"class":286},"    # Download VMX file.\n",[240,890,892,895,897,900,903,906,909,912,915,918,921],{"class":242,"line":891},72,[240,893,894],{"class":246},"    $dsname ",[240,896,592],{"class":250},[240,898,899],{"class":246}," $VMPathName.Split(",[240,901,902],{"class":262},"\" \"",[240,904,905],{"class":246},")[",[240,907,908],{"class":293},"0",[240,910,911],{"class":246},"].TrimStart(",[240,913,914],{"class":262},"\"[\"",[240,916,917],{"class":246},").TrimEnd(",[240,919,920],{"class":262},"\"]\"",[240,922,477],{"class":246},[240,924,926,929,931,933,936,938,941,943,946],{"class":242,"line":925},73,[240,927,928],{"class":246},"    $vmRelativePath ",[240,930,592],{"class":250},[240,932,899],{"class":246},[240,934,935],{"class":262},"']'",[240,937,905],{"class":246},[240,939,940],{"class":293},"1",[240,942,911],{"class":246},[240,944,945],{"class":262},"' '",[240,947,477],{"class":246},[240,949,951,954,956,959,961],{"class":242,"line":950},74,[240,952,953],{"class":293},"    Remove-PSDrive",[240,955,266],{"class":250},[240,957,958],{"class":246},"Name fromds ",[240,960,251],{"class":250},[240,962,963],{"class":246},"ErrorAction SilentlyContinue\n",[240,965,967,970,972,974,976,979,982,985,987,990,992,995,998,1001],{"class":242,"line":966},75,[240,968,969],{"class":293},"    New-PSDrive",[240,971,266],{"class":250},[240,973,958],{"class":246},[240,975,251],{"class":250},[240,977,978],{"class":246},"Location (",[240,980,981],{"class":293},"Get-Datastore",[240,983,984],{"class":246}," $dsname) ",[240,986,251],{"class":250},[240,988,989],{"class":246},"PSProvider VimDatastore ",[240,991,251],{"class":250},[240,993,994],{"class":246},"Root ",[240,996,997],{"class":262},"'\u002F'",[240,999,1000],{"class":250}," |",[240,1002,1003],{"class":293}," Out-Null\n",[240,1005,1007,1010,1012,1015,1018,1020,1023,1026,1028,1031,1033,1035,1037],{"class":242,"line":1006},76,[240,1008,1009],{"class":246},"    $dlvmx ",[240,1011,592],{"class":250},[240,1013,1014],{"class":246}," $outvmxdir ",[240,1016,1017],{"class":250},"+",[240,1019,504],{"class":246},[240,1021,1022],{"class":262},"\"\u002F\"",[240,1024,1025],{"class":246},") ",[240,1027,1017],{"class":250},[240,1029,1030],{"class":246}," $vmRelativePath.Split(",[240,1032,997],{"class":262},[240,1034,905],{"class":246},[240,1036,940],{"class":293},[240,1038,1039],{"class":246},"]\n",[240,1041,1043,1046,1048,1051],{"class":242,"line":1042},77,[240,1044,1045],{"class":246},"    $checkforoutfile ",[240,1047,592],{"class":250},[240,1049,1050],{"class":293}," Test-Path",[240,1052,1053],{"class":246}," $dlvmx\n",[240,1055,1057,1060],{"class":242,"line":1056},78,[240,1058,1059],{"class":250},"    if",[240,1061,1062],{"class":246}," ($checkforoutfile) {\n",[240,1064,1066,1069],{"class":242,"line":1065},79,[240,1067,1068],{"class":293},"        Remove-Item",[240,1070,1053],{"class":246},[240,1072,1074],{"class":242,"line":1073},80,[240,1075,1076],{"class":246},"    }\n",[240,1078,1080,1083,1085,1088,1090,1093,1095],{"class":242,"line":1079},81,[240,1081,1082],{"class":293},"    Copy-DatastoreItem",[240,1084,266],{"class":250},[240,1086,1087],{"class":246},"Item fromds:\\$vmRelativePath ",[240,1089,251],{"class":250},[240,1091,1092],{"class":246},"Destination $outvmxdir ",[240,1094,251],{"class":250},[240,1096,1097],{"class":246},"Force\n",[240,1099,1101],{"class":242,"line":1100},82,[240,1102,484],{"emptyLinePlaceholder":483},[240,1104,1106],{"class":242,"line":1105},83,[240,1107,1108],{"class":286},"    # Update VMX file to -51 file without vShield lines.\n",[240,1110,1112,1115,1117,1119,1121,1123,1125],{"class":242,"line":1111},84,[240,1113,1114],{"class":246},"    $vmxfile ",[240,1116,592],{"class":250},[240,1118,899],{"class":246},[240,1120,1022],{"class":262},[240,1122,905],{"class":246},[240,1124,940],{"class":293},[240,1126,1039],{"class":246},[240,1128,1130,1133,1135,1137,1139,1142,1145],{"class":242,"line":1129},85,[240,1131,1132],{"class":246},"    $vmxsource ",[240,1134,592],{"class":250},[240,1136,1014],{"class":246},[240,1138,1017],{"class":250},[240,1140,1141],{"class":262}," \"\\\"",[240,1143,1144],{"class":250}," +",[240,1146,1147],{"class":246}," $vmxfile\n",[240,1149,1151,1154,1156,1159,1161,1163,1165,1168,1171,1174,1176],{"class":242,"line":1150},86,[240,1152,1153],{"class":246},"    $vmxdest ",[240,1155,592],{"class":250},[240,1157,1158],{"class":246}," $outvmxnewdir ",[240,1160,1017],{"class":250},[240,1162,1141],{"class":262},[240,1164,1144],{"class":250},[240,1166,1167],{"class":246}," [",[240,1169,1170],{"class":250},"System.IO.Path",[240,1172,1173],{"class":246},"]::GetFileNameWithoutExtension($vmxfile) ",[240,1175,1017],{"class":250},[240,1177,1178],{"class":262}," \"-51.vmx\"\n",[240,1180,1182,1184,1186,1188],{"class":242,"line":1181},87,[240,1183,1045],{"class":246},[240,1185,592],{"class":250},[240,1187,1050],{"class":293},[240,1189,1190],{"class":246}," $vmxdest\n",[240,1192,1194,1196],{"class":242,"line":1193},88,[240,1195,1059],{"class":250},[240,1197,1062],{"class":246},[240,1199,1201,1203],{"class":242,"line":1200},89,[240,1202,1068],{"class":293},[240,1204,1190],{"class":246},[240,1206,1208],{"class":242,"line":1207},90,[240,1209,1076],{"class":246},[240,1211,1213,1216,1219,1221,1223,1225,1227,1230,1233,1236,1239,1241,1244,1246,1248,1251],{"class":242,"line":1212},91,[240,1214,1215],{"class":293},"    Get-Content",[240,1217,1218],{"class":246}," $vmxsource ",[240,1220,746],{"class":250},[240,1222,749],{"class":293},[240,1224,752],{"class":246},[240,1226,755],{"class":293},[240,1228,1229],{"class":250}," -notmatch",[240,1231,1232],{"class":262}," 'VFILE.globaloptions'",[240,1234,1235],{"class":250}," -and",[240,1237,1238],{"class":293}," $_",[240,1240,1229],{"class":250},[240,1242,1243],{"class":262}," 'scsi0:0.filters = \"VFILE\"'",[240,1245,767],{"class":246},[240,1247,746],{"class":250},[240,1249,1250],{"class":293}," Set-Content",[240,1252,1190],{"class":246},[240,1254,1256,1259,1262,1265,1268],{"class":242,"line":1255},92,[240,1257,1258],{"class":293},"    Add-Content",[240,1260,1261],{"class":246}," $vmxdest ",[240,1263,1264],{"class":262},"\"",[240,1266,1267],{"class":293},"`n",[240,1269,1270],{"class":262},"#Modified to remove VFILE Lines\"\n",[240,1272,1274],{"class":242,"line":1273},93,[240,1275,484],{"emptyLinePlaceholder":483},[240,1277,1279],{"class":242,"line":1278},94,[240,1280,1281],{"class":286},"    # Upload new VMX file to datastore.\n",[240,1283,1285,1287],{"class":242,"line":1284},95,[240,1286,516],{"class":293},[240,1288,1190],{"class":246},[240,1290,1292,1295,1297,1300,1303,1306,1308,1311,1313,1315],{"class":242,"line":1291},96,[240,1293,1294],{"class":246},"    $vmxupload ",[240,1296,592],{"class":250},[240,1298,1299],{"class":246}," ($vmRelativePath ",[240,1301,1302],{"class":250},"-replace",[240,1304,1305],{"class":262}," '\\.vmx$'",[240,1307,778],{"class":250},[240,1309,1310],{"class":262}," ''",[240,1312,1025],{"class":246},[240,1314,1017],{"class":250},[240,1316,1178],{"class":262},[240,1318,1320,1322],{"class":242,"line":1319},97,[240,1321,516],{"class":293},[240,1323,1324],{"class":246}," $vmxupload\n",[240,1326,1328,1330,1332,1335,1337,1340,1342],{"class":242,"line":1327},98,[240,1329,1082],{"class":293},[240,1331,266],{"class":250},[240,1333,1334],{"class":246},"Item $vmxdest ",[240,1336,251],{"class":250},[240,1338,1339],{"class":246},"Destination fromds:\\$vmxupload ",[240,1341,251],{"class":250},[240,1343,1097],{"class":246},[240,1345,1347],{"class":242,"line":1346},99,[240,1348,484],{"emptyLinePlaceholder":483},[240,1350,1352],{"class":242,"line":1351},100,[240,1353,1354],{"class":286},"    # Set array for addition of VMs.\n",[240,1356,1358,1361,1363,1366],{"class":242,"line":1357},101,[240,1359,1360],{"class":246},"    $obj ",[240,1362,592],{"class":250},[240,1364,1365],{"class":293}," New-Object",[240,1367,1368],{"class":246}," PSObject\n",[240,1370,1372,1374,1376,1379,1381,1384,1386,1389,1392,1394],{"class":242,"line":1371},102,[240,1373,1360],{"class":246},[240,1375,746],{"class":250},[240,1377,1378],{"class":293}," Add-Member",[240,1380,266],{"class":250},[240,1382,1383],{"class":246},"MemberType NoteProperty ",[240,1385,251],{"class":250},[240,1387,1388],{"class":246},"Name ",[240,1390,1391],{"class":262},"\"VMName\"",[240,1393,266],{"class":250},[240,1395,1396],{"class":246},"Value $vname\n",[240,1398,1400,1402,1404,1406,1408,1410,1412,1414,1417,1419],{"class":242,"line":1399},103,[240,1401,1360],{"class":246},[240,1403,746],{"class":250},[240,1405,1378],{"class":293},[240,1407,266],{"class":250},[240,1409,1383],{"class":246},[240,1411,251],{"class":250},[240,1413,1388],{"class":246},[240,1415,1416],{"class":262},"\"VMDatastore\"",[240,1418,266],{"class":250},[240,1420,1421],{"class":246},"Value $dsname\n",[240,1423,1425,1427,1429,1431,1433,1435,1437,1439,1442,1444],{"class":242,"line":1424},104,[240,1426,1360],{"class":246},[240,1428,746],{"class":250},[240,1430,1378],{"class":293},[240,1432,266],{"class":250},[240,1434,1383],{"class":246},[240,1436,251],{"class":250},[240,1438,1388],{"class":246},[240,1440,1441],{"class":262},"\"VMPathName\"",[240,1443,266],{"class":250},[240,1445,1446],{"class":246},"Value $vmxupload\n",[240,1448,1450,1453,1456],{"class":242,"line":1449},105,[240,1451,1452],{"class":246},"    $aVMInfo ",[240,1454,1455],{"class":250},"+=",[240,1457,1458],{"class":246}," $obj\n",[240,1460,1462],{"class":242,"line":1461},106,[240,1463,531],{"class":246},[240,1465,1467],{"class":242,"line":1466},107,[240,1468,484],{"emptyLinePlaceholder":483},[240,1470,1472,1475,1477,1479,1481],{"class":242,"line":1471},108,[240,1473,1474],{"class":293},"Remove-PSDrive",[240,1476,266],{"class":250},[240,1478,958],{"class":246},[240,1480,251],{"class":250},[240,1482,963],{"class":246},[240,1484,1486,1489,1492,1494,1497,1499,1502],{"class":242,"line":1485},109,[240,1487,1488],{"class":293},"Disconnect-VIServer",[240,1490,1491],{"class":246}," $vcServer4 ",[240,1493,251],{"class":250},[240,1495,1496],{"class":246},"Force ",[240,1498,251],{"class":250},[240,1500,1501],{"class":246},"Confirm:",[240,1503,1504],{"class":293},"$false\n",[240,1506,1508,1511],{"class":242,"line":1507},110,[240,1509,1510],{"class":293},"Start-Sleep",[240,1512,1513],{"class":293}," 5\n",[240,1515,1517],{"class":242,"line":1516},111,[240,1518,484],{"emptyLinePlaceholder":483},[240,1520,1522],{"class":242,"line":1521},112,[240,1523,1524],{"class":286},"# Connect to vCenter 5.1 server.\n",[240,1526,1528,1530],{"class":242,"line":1527},113,[240,1529,719],{"class":293},[240,1531,1532],{"class":246}," $vcServer5\n",[240,1534,1536,1539,1541,1544],{"class":242,"line":1535},114,[240,1537,1538],{"class":246},"$VMFolder ",[240,1540,592],{"class":250},[240,1542,1543],{"class":293}," Get-Folder",[240,1545,1546],{"class":246}," $VMFolderName\n",[240,1548,1550],{"class":242,"line":1549},115,[240,1551,484],{"emptyLinePlaceholder":483},[240,1553,1555],{"class":242,"line":1554},116,[240,1556,1557],{"class":286},"# Import VM to vCenter 5.1.\n",[240,1559,1561,1563,1565,1567],{"class":242,"line":1560},117,[240,1562,801],{"class":250},[240,1564,804],{"class":246},[240,1566,807],{"class":250},[240,1568,1569],{"class":246}," $aVMInfo) {\n",[240,1571,1573,1575,1577],{"class":242,"line":1572},118,[240,1574,816],{"class":246},[240,1576,592],{"class":250},[240,1578,1579],{"class":246}," $vm.VMName\n",[240,1581,1583,1586,1588],{"class":242,"line":1582},119,[240,1584,1585],{"class":246},"    $datastore ",[240,1587,592],{"class":250},[240,1589,1590],{"class":246}," $vm.VMDatastore\n",[240,1592,1594,1597,1599],{"class":242,"line":1593},120,[240,1595,1596],{"class":246},"    $VMPath ",[240,1598,592],{"class":250},[240,1600,1601],{"class":246}," $vm.VMPathName\n",[240,1603,1605,1607],{"class":242,"line":1604},121,[240,1606,516],{"class":293},[240,1608,829],{"class":246},[240,1610,1612,1614],{"class":242,"line":1611},122,[240,1613,516],{"class":293},[240,1615,1616],{"class":246}," $datastore\n",[240,1618,1620,1622],{"class":242,"line":1619},123,[240,1621,516],{"class":293},[240,1623,1624],{"class":246}," $VMPath\n",[240,1626,1628,1631,1633,1636,1638,1641,1643,1646,1648],{"class":242,"line":1627},124,[240,1629,1630],{"class":246},"    $VMFullPath ",[240,1632,592],{"class":250},[240,1634,1635],{"class":262}," \"[\"",[240,1637,1144],{"class":250},[240,1639,1640],{"class":246}," $datastore ",[240,1642,1017],{"class":250},[240,1644,1645],{"class":262}," \"] \"",[240,1647,1144],{"class":250},[240,1649,1624],{"class":246},[240,1651,1653,1655],{"class":242,"line":1652},125,[240,1654,516],{"class":293},[240,1656,1657],{"class":246}," $VMFullPath\n",[240,1659,1661,1664,1666,1669,1671,1674,1676,1679,1681,1684,1686],{"class":242,"line":1660},126,[240,1662,1663],{"class":293},"    New-VM",[240,1665,266],{"class":250},[240,1667,1668],{"class":246},"VMFilePath $VMFullPath ",[240,1670,251],{"class":250},[240,1672,1673],{"class":246},"VMHost $ESXHost ",[240,1675,251],{"class":250},[240,1677,1678],{"class":246},"Location $VMFolder ",[240,1680,251],{"class":250},[240,1682,1683],{"class":246},"ResourcePool $ResPool ",[240,1685,746],{"class":250},[240,1687,1003],{"class":293},[240,1689,1691],{"class":242,"line":1690},127,[240,1692,531],{"class":246},[240,1694,1696],{"class":242,"line":1695},128,[240,1697,484],{"emptyLinePlaceholder":483},[240,1699,1701,1703,1706,1708,1710,1712,1714],{"class":242,"line":1700},129,[240,1702,1488],{"class":293},[240,1704,1705],{"class":246}," $vcServer5 ",[240,1707,251],{"class":250},[240,1709,1496],{"class":246},[240,1711,251],{"class":250},[240,1713,1501],{"class":246},[240,1715,1504],{"class":293},[15,1717,1719],{"id":1718},"notes","Notes",[20,1721,1722,1729,1735],{},[23,1723,1724,1725,1728],{},"The original VMX files are left untouched. The modified copy is uploaded next to each original as ",[30,1726,1727],{},"\u003Cname>-51.vmx",", and that copy is what gets registered in vCenter 5.1.",[23,1730,1731,1732,294],{},"The script expects each VM to live in a single datastore folder of the form ",[30,1733,1734],{},"[datastore] \u003Cfolder>\u002F\u003Cname>.vmx",[23,1736,1737,1738,1741,1742,1744,1745,1744,1748,1751,1752,1755,1756,1759],{},"Update 2026-09-20 (v1.1): the import folder is now looked up after connecting to vCenter 5.1 (it previously ran before any connection, and its variable was overwritten inside the download loop, so ",[30,1739,1740],{},"New-VM -Location"," received a path string instead of the folder). VMX file names that contain ",[30,1743,294],{},", ",[30,1746,1747],{},"v",[30,1749,1750],{},"m"," or ",[30,1753,1754],{},"x"," are also no longer truncated, and the ",[30,1757,1758],{},"fromds:"," drive is removed at the end.",[1761,1762,1763],"style",{},"html pre.shiki code .sgsFI, html code.shiki .sgsFI{--shiki-default:#24292E}html pre.shiki code .sD7c4, html code.shiki .sD7c4{--shiki-default:#D73A49}html pre.shiki code .sYBdl, html code.shiki .sYBdl{--shiki-default:#032F62}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html pre.shiki code .sAwPA, html code.shiki .sAwPA{--shiki-default:#6A737D}html pre.shiki code .sYu0t, html code.shiki .sYu0t{--shiki-default:#005CC5}",{"title":236,"searchDepth":290,"depth":290,"links":1765},[1766,1767,1768,1769,1770],{"id":17,"depth":290,"text":18},{"id":56,"depth":290,"text":57},{"id":225,"depth":290,"text":226},{"id":275,"depth":290,"text":276},{"id":1718,"depth":290,"text":1719},"techcolumnist",[1773,1774],"ps","scripts","2013-10-25T14:41:24Z","1 environment. This created a slight issue due to the fact that environment ran vShield.","md",false,null,{},"\u002Fblog\u002F2013\u002F10\u002F25\u002Fpowershell-download-vmx-file-rename-upload-add-to-inventory",{"title":6,"description":1776},[1784,1771],"lasswell","both","blog\u002F2013\u002F10\u002F25\u002Fpowershell-download-vmx-file-rename-upload-add-to-inventory",[235,1788,1789],"vmware","vmx","2026-09-20T00:00:00Z","\u002F2013\u002F10\u002F25\u002Fpowershell-download-vmx-file-rename-upload-add-to-inventory\u002F","9tKfD4N6tz7XN8g3DEKphwFySP3QExhtfLNyEeYfths",{"title":1794,"description":1795,"date":1796,"url":1797,"categories":1798,"tags":1800,"image":1779,"readingTime":243,"canonical":1771,"sites":1803,"series":1779,"seriesOrder":1779},"cisco WS-C4900M: Set SSH","Note: You can leave the “telnet” off vty transport, but if you do ensure that you’ve tested SSH first!","2014-01-14T16:55:49Z","\u002F2014\u002F01\u002F14\u002Fcisco-ws-c4900m-set-ssh\u002F",[1799],"engineering",[1801,1802],"cisco","ssh",[1784,1771],{"title":1805,"description":1806,"date":1807,"url":1808,"categories":1809,"tags":1810,"image":1779,"readingTime":243,"canonical":1771,"sites":1811,"series":1779,"seriesOrder":1779},"PowerShell: List All VMs with Datastore","Script to list all the VMs that exist within your vCenter Server with their datastore.","2013-10-14T17:10:37Z","\u002F2013\u002F10\u002F14\u002Fscript-list-all-vms-with-datastore\u002F",[1773,1774],[235,1788],[1784,1771],[1804,1813,1822],{"title":1814,"description":1815,"date":1816,"url":1817,"categories":1818,"tags":1819,"image":1779,"readingTime":243,"canonical":1771,"sites":1821,"series":1779,"seriesOrder":1779},"PowerShell: Autotask – Enable Client Portal for All Users","This is a quick one, it’s been forever since I’ve posted here. After moving back to Autotask, there’s still a ton of things to automate.","2022-10-12T14:13:37Z","\u002F2022\u002F10\u002F12\u002Fautotask-powershell-enable-client-portal-for-all-users\u002F",[1773,1774],[1820,235],"autotask",[1784,1771],{"title":1823,"description":1824,"date":1825,"url":1826,"categories":1827,"tags":1828,"image":1779,"readingTime":243,"canonical":1771,"sites":1831,"series":1779,"seriesOrder":1779},"PowerShell: Get Exchange Mailboxes Over XXGB","Simple command turned crazy. I ended up coming up with this due to the fact we have duplicate display names and needed to update for Exchange Online to get mailbox sizes.","2021-02-18T14:46:29Z","\u002F2021\u002F02\u002F18\u002Fpowershell-get-exchange-mailboxes-over-xxgb\u002F",[1773,1774],[235,1829,1830],"exchange","exchange-online",[1784,1771],{"doc":1779,"posts":1833},[],1790949961039]