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,
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}}
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}}
Thanks this is what I'm looking for. Tested it and its working.