Skip to content

Instantly share code, notes, and snippets.

@fabricesemti80
Created March 3, 2023 10:52
Show Gist options
  • Save fabricesemti80/3aebff4b8f652ffb0852f229f046adea to your computer and use it in GitHub Desktop.
Save fabricesemti80/3aebff4b8f652ffb0852f229f046adea to your computer and use it in GitHub Desktop.
function Get-ContentLibraryItemPath {
<#
.NOTES
===========================================================================
Created by: Fabrice Semti
Date: 03 March 2023
Organization: VMware
Blog: http://www.fabricesemti.com
Twitter: @vBrianGraf
Github: https://github.com/fabricesemti80
===========================================================================
.SYNOPSIS
Cmdlet to return the folder path of your content library item
.DESCRIPTION
Returns path of a content library item
#>
param (
[parameter(ValueFromPipelineByPropertyName)]$DatastoreName = 'Vol-dc1clu01-Templates',
[parameter(ValueFromPipelineByPropertyName)]$Name = 'Rocky-9.1-x86_64-dvd',
[parameter(ValueFromPipelineByPropertyName)]$ItemType = 'iso',
[parameter(ValueFromPipelineByPropertyName)]$ContentLibrary = 'Olivers Yard Content library'
)
begin {
$Datastore = Get-Datastore $DatastoreName
#Get datastore view using id
$DSView = Get-View $Datastore.id
$Spec = New-Object VMware.Vim.HostDatastoreBrowserSearchSpec
$Browser = Get-View $DSView.browser
$DSName = ('[' + $Datastore.name + ']')
$search = $Browser.SearchDatastoreSubFolders($DSName, $Spec)
}
Process {
foreach ($Dir in $search) {
$ISOFile = $null
$DSFolder = (($Dir.FolderPath.Split(']').trimstart())[1]).trimend('/')
$ISOFile = ($Dir.file | Where-Object { $_.Path -like "$Name*.$itemtype" }).Path
if ($null -ne $Isofile) {
$ISOpath = "[$($Datastore.name)] $DSFolder/$ISOFile"
$ISOpath
}
}
}
end {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment