VMware Cloud Community
breakstuf50
Enthusiast
Enthusiast
Jump to solution

Need help making the Get-FolderPath script working

Hi Everyone,

I'm having hard time making this script work can someone help me on this. I was able to produce the csv file unfortunately there is no value/output on the PATH column. I'm thinking that I wasnt able to call the get-folderpath function correctly. Thanks.

------

$date = Get-Date -format M-d-yyyy

. 'c:\Users\Get-FolderPath.ps1'

$folders = Get-Folder -type vm | Get-FolderPath | Sort-Object Id

function Set-Path{

param($Object)

foreach ($folder IN $folders){

if( $folder.Id -eq $Object.Id){

$result = $folder.Path

break

}

}

$result

}

Get-VM  | Sort-Object FolderID | Select Name, Uid, NumCpu, MemoryGB, ProvisionedSpaceGB, @{N=”Path”;E={Set-Path -Object $_.Folder}}, ResourcePoolId, ResourcePool, @{N=”ToolsStatus”;E={$_.ExtensionData.Summary.Guest.ToolsVersionStatus}} | `

Export-Csv “C:\test\vm-vServer-$date.csv” -NoTypeInformation -UseCulture

-----------

Also when I try to run it directly on powercli I'm getting this errors

--------

scripts\Get-FolderPath.ps1:45 char:25

+         $fld = Get-View $fld.Parent

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

    + CategoryInfo          : InvalidData: (:) [Get-View], ParameterBindingVal

   idationException

    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutom

   ation.ViCore.Cmdlets.Commands.DotNetInterop.GetVIView

Get-View : Cannot validate argument on parameter 'VIObject'. The argument is

null, empty, or an element of the argument collection contains a null value.

Supply a collection that does not contain any null values and then try the

command again.

------

I'd like to get an output something like this. The most important is for me to get the folder path location.

VM Name | Datacenter | Cluster | NumCPU | MemoryGB | Provisioned SpaceGB | Folder Path |

Thanks in advance.

Cheers,

0 Kudos
1 Solution

Accepted Solutions
RvdNieuwendijk
Leadership
Leadership
Jump to solution

The following PowerCLI script will give you the desired information:

Get-VM | Select-Object -Property Name,@{N='Datacenter';E={$_|Get-Datacenter}},@{N='Cluster';E={$_.VMHost.Parent}},

NumCPU,MemoryGB,ProvisionedSpaceGB,@{N='Path';E={($_.Folder|Get-FolderPath).Path}}

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition

View solution in original post

0 Kudos
2 Replies
RvdNieuwendijk
Leadership
Leadership
Jump to solution

The following PowerCLI script will give you the desired information:

Get-VM | Select-Object -Property Name,@{N='Datacenter';E={$_|Get-Datacenter}},@{N='Cluster';E={$_.VMHost.Parent}},

NumCPU,MemoryGB,ProvisionedSpaceGB,@{N='Path';E={($_.Folder|Get-FolderPath).Path}}

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
breakstuf50
Enthusiast
Enthusiast
Jump to solution

Thanks this is what I'm looking for. Tested it and its working.

0 Kudos