VMware Cloud Community
xXvenszXx
Enthusiast
Enthusiast
Jump to solution

Export list of VMs with complete folder path

Hi all,

I´m not a scripter so I need your help for my environemnt - 1 vcenter 5 datacenters without templates.

I need an export in csv contains the BlueFolderPath, I found a lot of scripts using Get-Folder and Get-FolderPath (is not recognized as the name of a cmdlet) something like that but nothing is working.

example CSV:

AB
testvm1DATACENTER\Applications\Banking\external
testvm2DATACENTER\Applications\Banking
testvm3DATACENTER\
testvm4DATACENTER\Applications

I found a lot of scripts from LucD but I think I´m to stuipd to get it to fly.

Get the folderpath - LucD notes

Folder by Path - LucD notes

I hope someone can help me Smiley Sad

Thanks a lot

Greetings

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Sorry, I'm must have had a black out.

The Get-FolderPath only works for Folder objects, not VM.

But you can use the function from my Get-InventoryPlus – Inventory Of All VSphere Objects post.

I attach a script that will list all the VMs, with their blue and yellow folder path.


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

View solution in original post

49 Replies
LucD
Leadership
Leadership
Jump to solution

What errors are you getting?

Can you attach the script your are using, and preferably a screenshot of the run.


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

Reply
0 Kudos
ScottDriver42
Enthusiast
Enthusiast
Jump to solution

do you have the snappin/module loaded? You should see VMware.VimAutomation.Core returned under either a get-pssnapin or get-module

Blog: https://virtualvt.wordpress.com/ | Twitter: VTsnowboarder42
Reply
0 Kudos
xXvenszXx
Enthusiast
Enthusiast
Jump to solution

Oh damn, I´m such a script newby... I don´t read line 1 - -pssnapin VMware.VimAutomation.Core -version 4.1

I want to use this script: Get the folderpath - LucD notes I think it´s the right one for me.

How can I use version 4.1 when I have installed pCLI 6.5?

Get-PowerCLIVersion

PowerCLI Version
----------------
   VMware PowerCLI 6.5 Release 1 build 4624819
---------------
Component Versions
---------------
   VMware Cis Core PowerCLI Component 6.5 build 4624453
   VMware VimAutomation Core PowerCLI Component 6.5 build 4624450
   VMWare ImageBuilder PowerCLI Component 6.5 build 4561891
   VMWare AutoDeploy PowerCLI Component 6.5 build 4561891
   VMware Vds PowerCLI Component 6.5 build 4624695
   VMware Cloud PowerCLI Component 6.5 build 4624821
   VMware HA PowerCLI Component 6.0 build 4525225
   VMware HorizonView PowerCLI Component 7.0.2 build 4596620
   VMware Licensing PowerCLI Component 6.5 build 4624822
   VMware PCloud PowerCLI Component 6.5 build 4624825
   VMware Storage PowerCLI Component 6.5 build 4624820
   VMware vROps PowerCLI Component 6.5 build 4624824
   VMware vSphere Update Manager PowerCLI 6.5 build 4540462

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You don't need 4.1, just remove that #requires line.

It will work with 6.5R1 as well


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

Reply
0 Kudos
xXvenszXx
Enthusiast
Enthusiast
Jump to solution

Good morning,

I deleted the comments from the script. Now I get no error but the script is doing nothing. Should I put a Name of a folder in  HelpMessage = "Enter a folder")] ? Is it possible to dump it into a file?

Must I use pCLI 6.0 when I use VMware 6.0U2 or should it also work with pCLI 6.5?

When I use Get-Folder | Get-FolderPath I get an error - see attached picture.

Thanks a lot for your help :smileygrin:

FodlerPath.JPG

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I assume you have placed the function in that .ps1 file.

In that case you need to dot-source it, like this

. .\FolderPath.ps1

There is a blank between the two dots.


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

Reply
0 Kudos
xXvenszXx
Enthusiast
Enthusiast
Jump to solution

Yes the script is on my desktop in the "FolderPath.ps1".

Empty screen also with ". .\FolderPath.ps1"

FP.JPG

FP2.JPG

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

The empty screen is normal.

But is the function known, can you call it?

path.png


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

Reply
0 Kudos
xXvenszXx
Enthusiast
Enthusiast
Jump to solution

Where is the output of the VMs/folder names?

FP.JPG

FP.JPG

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Now I'm confused, you execute 'Get-Command -Name Get-FolderPath' twice.

One time it returns ok, the second call the function is not found anymore.

Did you stop the PowerShell session in between?

Did you dot-source the .ps1 file?

The output of the function is displayed on the console

.path.png


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

Reply
0 Kudos
xXvenszXx
Enthusiast
Enthusiast
Jump to solution

Now, I´m confused - must I need Windows PowerShell oder VMware Power CLI?

FP.JPG

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Both!
PowerCLI is an add-on on top of PowerShell.

When you start the session from the PowerCLI shortcut, the PowerCLI initialisation script starts PowerShell and loads the required PSSnapin and/or modules (PSSnapin or modules depends on the PowerCLI version you have installed).

From the PowerCLI prompt you can see that you are running PowerShell with PowerCLI loaded (6.5R1 in my case, which means only modules)..

pcli.png

Once in the session, you can "load" functions that you have stored in .ps1 files, by dot-sourcing them.

Once these functions are known to PowerShell, you can invoke them (see me previous answer).


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

Reply
0 Kudos
xXvenszXx
Enthusiast
Enthusiast
Jump to solution

Get-Module show nothing:

FP.JPG

FP.JPG

I don´t understand something...where is the output from the script?

FP.JPG

Reply
0 Kudos
xXvenszXx
Enthusiast
Enthusiast
Jump to solution

Oh my goooooooood.

Now I understand your script - I can load it and use Get-FolderPath :smileyblush:

So how can I create a dump to csv from the whole vcenter with this structure sorted by DC?

AB
testvm1DATACENTER\Applications\Banking\external
testvm2DATACENTER\Applications\Banking
testvm3DATACENTER\
testvm4DATACENTER\Applications

Something like that: Get-VM | Get-FolderPath?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Just pipe the result to the Export-Csv cmdlet.

Get-VM | Get-FolderPath | Export-Csv report.csv -NoTypeInformation -UseCulture


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

Reply
0 Kudos
xXvenszXx
Enthusiast
Enthusiast
Jump to solution

I got this error by using Get-VM in combination with Get-FolderPath - both commands are working alone:

FP.JPG

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Sorry, I'm must have had a black out.

The Get-FolderPath only works for Folder objects, not VM.

But you can use the function from my Get-InventoryPlus – Inventory Of All VSphere Objects post.

I attach a script that will list all the VMs, with their blue and yellow folder path.


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

xXvenszXx
Enthusiast
Enthusiast
Jump to solution

Hi LucD,

wow great script and that is what I need.

Is it possible to show only type = VirtualMachine that the script is running faster and the csv is not so big?

Get-InventoryPlus | ? Type -eq VirtualMachine | Export-Csv -Path C:\temp\VMsrport.csv -NoTypeInformation -UseCulture

I don´t know if i use the -eq right but my csv is empty. Smiley Sad

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That should be ok.

Are you connected to a vCenter?

Is there anything in $global:defaultviservers


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

Reply
0 Kudos