[{"data":1,"prerenderedAt":672},["ShallowReactive",2],{"post:\u002F2013\u002F10\u002F14\u002Fscript-list-all-vms-with-datastore\u002F":3},{"post":4,"newer":633,"older":642,"related":651,"series":670},{"id":5,"title":6,"body":7,"canonical":613,"categories":614,"date":617,"description":13,"extension":618,"featured":619,"hero":620,"image":620,"meta":621,"navigation":337,"path":622,"readingTime":130,"seo":623,"series":620,"seriesOrder":620,"sites":624,"source":626,"stem":627,"tags":628,"updated":630,"url":631,"__hash__":632},"blog\u002Fblog\u002F2013\u002F10\u002F14\u002Fscript-list-all-vms-with-datastore.md","PowerShell: List All VMs with Datastore",{"type":8,"value":9,"toc":606},"minimark",[10,14,19,48,52,110,114,117,149,175,179,586,590,602],[11,12,13],"p",{},"Script to list all the VMs that exist within your vCenter Server with their datastore.",[15,16,18],"h2",{"id":17},"requirements","Requirements",[20,21,22,31,38,41],"ul",{},[23,24,25,26,30],"li",{},"Windows PowerShell with VMware vSphere PowerCLI installed. The script loads the ",[27,28,29],"code",{},"VMware.VimAutomation.Core"," snap-in, so it needs a PowerCLI release that ships it (5.x era).",[23,32,33,34,37],{},"A vCenter account that can read datacenters, datastores and VMs. ",[27,35,36],{},"Connect-VIServer"," prompts for credentials.",[23,39,40],{},"Network access to the vCenter Server.",[23,42,43,44,47],{},"A ",[27,45,46],{},"D:\\scripts"," folder, or change the export path.",[15,49,51],{"id":50},"parameters","Parameters",[53,54,55,74],"table",{},[56,57,58],"thead",{},[59,60,61,65,68,71],"tr",{},[62,63,64],"th",{},"Name",[62,66,67],{},"Type",[62,69,70],{},"Required",[62,72,73],{},"Description",[75,76,77,94],"tbody",{},[59,78,79,85,88,91],{},[80,81,82],"td",{},[27,83,84],{},"vcServer",[80,86,87],{},"String",[80,89,90],{},"Yes",[80,92,93],{},"Name or address of the vCenter Server. The script exits with a message if it is missing.",[59,95,96,101,104,107],{},[80,97,98],{},[27,99,100],{},"D:\\scripts\\datastore-output.csv",[80,102,103],{},"Path",[80,105,106],{},"No",[80,108,109],{},"Edit in the script: where the CSV is written.",[15,111,113],{"id":112},"usage","Usage",[11,115,116],{},"Pass the vCenter Server name and sign in when prompted.",[118,119,124],"pre",{"className":120,"code":121,"language":122,"meta":123,"style":123},"language-powershell shiki shiki-themes github-dark",".\\Get-VMDatastore.ps1 -vcServer vcenter.example.com\n","powershell","",[27,125,126],{"__ignoreMap":123},[127,128,131,135,139,143,146],"span",{"class":129,"line":130},"line",1,[127,132,134],{"class":133},"s95oV",".",[127,136,138],{"class":137},"sDLfK","\\Get-VMDatastore.ps1",[127,140,142],{"class":141},"snl16"," -",[127,144,145],{"class":133},"vcServer ",[127,147,148],{"class":137},"vcenter.example.com\n",[11,150,151,152,154,155,157,158,157,161,157,164,157,167,170,171,174],{},"The results are written to ",[27,153,100],{},", one row per VM and datastore, with ",[27,156,64],{},", ",[27,159,160],{},"DataStore",[27,162,163],{},"VMHost",[27,165,166],{},"PowerState",[27,168,169],{},"Version"," and ",[27,172,173],{},"Folder"," columns.",[15,176,178],{"id":177},"script","Script",[118,180,182],{"className":120,"code":181,"language":122,"meta":123,"style":123},"\u003C#\n.SYNOPSIS\n    Lists all VMs in a vCenter Server together with their datastore.\n.DESCRIPTION\n    Connects to the vCenter Server, walks every datastore in every datacenter and collects the VMs\n    stored on it (name, datastore, host, power state, hardware version and folder). The result is\n    written to D:\\scripts\\datastore-output.csv and the session is disconnected.\n.PARAMETER vcServer\n    Name or address of the vCenter Server. The script exits with a message if it is missing.\n.EXAMPLE\n    .\\Get-VMDatastore.ps1 -vcServer vcenter.example.com\n.NOTES\n    Author  : Thomas Lasswell (https:\u002F\u002Fwww.techcolumnist.com)\n    Version : 1.1 (2026-09-20)\n    History : 1.0 2013-10-14 Initial version.\n              1.1 2026-09-20 Disconnects without a confirmation prompt.\n    Requires: VMware PowerCLI with the VMware.VimAutomation.Core snap-in\n#>\nparam(\n    [string]$vcServer\n)\n\nClear-Host\n\nif (!$vcServer) {\n    Write-Host \"No vCenter Server Specified\"\n    exit\n}\n\nAdd-PSSnapin VMware.VimAutomation.Core\n$host.UI.RawUI.WindowTitle = \"PowerShell [PowerCLI Module Loaded]\"\n\nConnect-VIServer $vcServer\n\n$aDatastoreVM = Get-Datacenter | Get-Datastore | ForEach-Object {\n    $ds = $_.Name\n    $_ | Get-VM | Select-Object Name, @{n = 'DataStore'; e = { $ds } }, VMHost, PowerState, Version, Folder\n}\n\n$aDatastoreVM | Export-Csv \"D:\\scripts\\datastore-output.csv\" -NoTypeInformation -UseCulture\nDisconnect-VIServer $vcServer -Confirm:$false\n",[27,183,184,190,198,204,212,218,224,230,241,247,255,261,269,275,281,287,293,299,305,314,326,332,339,345,350,365,375,381,387,392,401,416,421,429,434,459,473,534,539,544,569],{"__ignoreMap":123},[127,185,186],{"class":129,"line":130},[127,187,189],{"class":188},"sAwPA","\u003C#\n",[127,191,193,195],{"class":129,"line":192},2,[127,194,134],{"class":137},[127,196,197],{"class":141},"SYNOPSIS\n",[127,199,201],{"class":129,"line":200},3,[127,202,203],{"class":188},"    Lists all VMs in a vCenter Server together with their datastore.\n",[127,205,207,209],{"class":129,"line":206},4,[127,208,134],{"class":137},[127,210,211],{"class":141},"DESCRIPTION\n",[127,213,215],{"class":129,"line":214},5,[127,216,217],{"class":188},"    Connects to the vCenter Server, walks every datastore in every datacenter and collects the VMs\n",[127,219,221],{"class":129,"line":220},6,[127,222,223],{"class":188},"    stored on it (name, datastore, host, power state, hardware version and folder). The result is\n",[127,225,227],{"class":129,"line":226},7,[127,228,229],{"class":188},"    written to D:\\scripts\\datastore-output.csv and the session is disconnected.\n",[127,231,233,235,238],{"class":129,"line":232},8,[127,234,134],{"class":137},[127,236,237],{"class":141},"PARAMETER",[127,239,240],{"class":141}," vcServer\n",[127,242,244],{"class":129,"line":243},9,[127,245,246],{"class":188},"    Name or address of the vCenter Server. The script exits with a message if it is missing.\n",[127,248,250,252],{"class":129,"line":249},10,[127,251,134],{"class":137},[127,253,254],{"class":141},"EXAMPLE\n",[127,256,258],{"class":129,"line":257},11,[127,259,260],{"class":188},"    .\\Get-VMDatastore.ps1 -vcServer vcenter.example.com\n",[127,262,264,266],{"class":129,"line":263},12,[127,265,134],{"class":137},[127,267,268],{"class":141},"NOTES\n",[127,270,272],{"class":129,"line":271},13,[127,273,274],{"class":188},"    Author  : Thomas Lasswell (https:\u002F\u002Fwww.techcolumnist.com)\n",[127,276,278],{"class":129,"line":277},14,[127,279,280],{"class":188},"    Version : 1.1 (2026-09-20)\n",[127,282,284],{"class":129,"line":283},15,[127,285,286],{"class":188},"    History : 1.0 2013-10-14 Initial version.\n",[127,288,290],{"class":129,"line":289},16,[127,291,292],{"class":188},"              1.1 2026-09-20 Disconnects without a confirmation prompt.\n",[127,294,296],{"class":129,"line":295},17,[127,297,298],{"class":188},"    Requires: VMware PowerCLI with the VMware.VimAutomation.Core snap-in\n",[127,300,302],{"class":129,"line":301},18,[127,303,304],{"class":188},"#>\n",[127,306,308,311],{"class":129,"line":307},19,[127,309,310],{"class":141},"param",[127,312,313],{"class":133},"(\n",[127,315,317,320,323],{"class":129,"line":316},20,[127,318,319],{"class":133},"    [",[127,321,322],{"class":141},"string",[127,324,325],{"class":133},"]$vcServer\n",[127,327,329],{"class":129,"line":328},21,[127,330,331],{"class":133},")\n",[127,333,335],{"class":129,"line":334},22,[127,336,338],{"emptyLinePlaceholder":337},true,"\n",[127,340,342],{"class":129,"line":341},23,[127,343,344],{"class":137},"Clear-Host\n",[127,346,348],{"class":129,"line":347},24,[127,349,338],{"emptyLinePlaceholder":337},[127,351,353,356,359,362],{"class":129,"line":352},25,[127,354,355],{"class":141},"if",[127,357,358],{"class":133}," (",[127,360,361],{"class":141},"!",[127,363,364],{"class":133},"$vcServer) {\n",[127,366,368,371],{"class":129,"line":367},26,[127,369,370],{"class":137},"    Write-Host",[127,372,374],{"class":373},"sU2Wk"," \"No vCenter Server Specified\"\n",[127,376,378],{"class":129,"line":377},27,[127,379,380],{"class":141},"    exit\n",[127,382,384],{"class":129,"line":383},28,[127,385,386],{"class":133},"}\n",[127,388,390],{"class":129,"line":389},29,[127,391,338],{"emptyLinePlaceholder":337},[127,393,395,398],{"class":129,"line":394},30,[127,396,397],{"class":137},"Add-PSSnapin",[127,399,400],{"class":133}," VMware.VimAutomation.Core\n",[127,402,404,407,410,413],{"class":129,"line":403},31,[127,405,406],{"class":137},"$host",[127,408,409],{"class":133},".UI.RawUI.WindowTitle ",[127,411,412],{"class":141},"=",[127,414,415],{"class":373}," \"PowerShell [PowerCLI Module Loaded]\"\n",[127,417,419],{"class":129,"line":418},32,[127,420,338],{"emptyLinePlaceholder":337},[127,422,424,426],{"class":129,"line":423},33,[127,425,36],{"class":137},[127,427,428],{"class":133}," $vcServer\n",[127,430,432],{"class":129,"line":431},34,[127,433,338],{"emptyLinePlaceholder":337},[127,435,437,440,442,445,448,451,453,456],{"class":129,"line":436},35,[127,438,439],{"class":133},"$aDatastoreVM ",[127,441,412],{"class":141},[127,443,444],{"class":137}," Get-Datacenter",[127,446,447],{"class":141}," |",[127,449,450],{"class":137}," Get-Datastore",[127,452,447],{"class":141},[127,454,455],{"class":137}," ForEach-Object",[127,457,458],{"class":133}," {\n",[127,460,462,465,467,470],{"class":129,"line":461},36,[127,463,464],{"class":133},"    $ds ",[127,466,412],{"class":141},[127,468,469],{"class":137}," $_",[127,471,472],{"class":133},".Name\n",[127,474,476,479,481,484,486,489,492,495,498,501,503,506,509,511,514,516,519,521,524,526,529,531],{"class":129,"line":475},37,[127,477,478],{"class":137},"    $_",[127,480,447],{"class":141},[127,482,483],{"class":137}," Get-VM",[127,485,447],{"class":141},[127,487,488],{"class":137}," Select-Object",[127,490,491],{"class":133}," Name",[127,493,494],{"class":141},",",[127,496,497],{"class":141}," @",[127,499,500],{"class":133},"{n ",[127,502,412],{"class":141},[127,504,505],{"class":373}," 'DataStore'",[127,507,508],{"class":133},"; e ",[127,510,412],{"class":141},[127,512,513],{"class":133}," { $ds } }",[127,515,494],{"class":141},[127,517,518],{"class":133}," VMHost",[127,520,494],{"class":141},[127,522,523],{"class":133}," PowerState",[127,525,494],{"class":141},[127,527,528],{"class":133}," Version",[127,530,494],{"class":141},[127,532,533],{"class":133}," Folder\n",[127,535,537],{"class":129,"line":536},38,[127,538,386],{"class":133},[127,540,542],{"class":129,"line":541},39,[127,543,338],{"emptyLinePlaceholder":337},[127,545,547,549,552,555,558,560,563,566],{"class":129,"line":546},40,[127,548,439],{"class":133},[127,550,551],{"class":141},"|",[127,553,554],{"class":137}," Export-Csv",[127,556,557],{"class":373}," \"D:\\scripts\\datastore-output.csv\"",[127,559,142],{"class":141},[127,561,562],{"class":133},"NoTypeInformation ",[127,564,565],{"class":141},"-",[127,567,568],{"class":133},"UseCulture\n",[127,570,572,575,578,580,583],{"class":129,"line":571},41,[127,573,574],{"class":137},"Disconnect-VIServer",[127,576,577],{"class":133}," $vcServer ",[127,579,565],{"class":141},[127,581,582],{"class":133},"Confirm:",[127,584,585],{"class":137},"$false\n",[15,587,589],{"id":588},"notes","Notes",[20,591,592],{},[23,593,594,595,597,598,601],{},"Update 2026-09-20 (v1.1): ",[27,596,574],{}," now uses ",[27,599,600],{},"-Confirm:$false",", so an unattended run no longer stops at a confirmation prompt.",[603,604,605],"style",{},"html pre.shiki code .s95oV, html code.shiki .s95oV{--shiki-default:#E1E4E8}html pre.shiki code .sDLfK, html code.shiki .sDLfK{--shiki-default:#79B8FF}html pre.shiki code .snl16, html code.shiki .snl16{--shiki-default:#F97583}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 .sU2Wk, html code.shiki .sU2Wk{--shiki-default:#9ECBFF}",{"title":123,"searchDepth":192,"depth":192,"links":607},[608,609,610,611,612],{"id":17,"depth":192,"text":18},{"id":50,"depth":192,"text":51},{"id":112,"depth":192,"text":113},{"id":177,"depth":192,"text":178},{"id":588,"depth":192,"text":589},"techcolumnist",[615,616],"ps","scripts","2013-10-14T17:10:37Z","md",false,null,{},"\u002Fblog\u002F2013\u002F10\u002F14\u002Fscript-list-all-vms-with-datastore",{"title":6,"description":13},[625,613],"lasswell","both","blog\u002F2013\u002F10\u002F14\u002Fscript-list-all-vms-with-datastore",[122,629],"vmware","2026-09-20T00:00:00Z","\u002F2013\u002F10\u002F14\u002Fscript-list-all-vms-with-datastore\u002F","14tlUl8bPl-_tV9q0Csp9g_fkDaPbNpi0OlhaPDu_Lk",{"title":634,"description":635,"date":636,"url":637,"categories":638,"tags":639,"image":620,"readingTime":130,"canonical":613,"sites":641,"series":620,"seriesOrder":620},"PowerShell: Download VMX File, Rename, Upload, Add to Inventory","1 environment. This created a slight issue due to the fact that environment ran vShield.","2013-10-25T14:41:24Z","\u002F2013\u002F10\u002F25\u002Fpowershell-download-vmx-file-rename-upload-add-to-inventory\u002F",[615,616],[122,629,640],"vmx",[625,613],{"title":643,"description":644,"date":645,"url":646,"categories":647,"tags":648,"image":620,"readingTime":130,"canonical":613,"sites":650,"series":620,"seriesOrder":620},"Windows Folder Locations","A quick reference to Windows folder locations and the environment variables that point to them, such as %ALLUSERSPROFILE%.","2013-10-01T10:23:06Z","\u002F2013\u002F10\u002F01\u002Fwindows-folder-locations\u002F",[],[649],"windows",[625,613],[633,652,662],{"title":653,"description":654,"date":655,"url":656,"categories":657,"tags":658,"image":620,"readingTime":214,"canonical":613,"sites":661,"series":620,"seriesOrder":620},"PowerShell: Active Directory – Report Group Membership Sprawl","Rank AD security groups by nesting depth, transitive member count, ownership and staleness for an access review, plus a per-user Kerberos token size estimate.","2025-12-03T14:00:00Z","\u002F2025\u002F12\u002F03\u002Fpowershell-active-directory-report-group-membership-sprawl\u002F",[615,616],[122,659,660],"active-directory","reporting",[613],{"title":663,"description":664,"date":665,"url":666,"categories":667,"tags":668,"image":620,"readingTime":206,"canonical":613,"sites":669,"series":620,"seriesOrder":620},"PowerShell: Windows Server – Disable SMBv1 Fleet-Wide and Verify","A script that audits SMBv1 access (event 3000), disables the SMBv1 server and optional feature across Windows servers, and reports which ones still need a restart.","2025-11-26T14:00:00Z","\u002F2025\u002F11\u002F26\u002Fpowershell-windows-server-disable-smbv1-fleet-wide-and-verify-it-stuck\u002F",[615,616],[122,649],[613],{"doc":620,"posts":671},[],1790223956704]