private/import/Find-PSDriveBootImage.ps1
function Find-PSDriveBootImage { [CmdletBinding()] [OutputType([System.IO.FileSystemInfo])] param () #================================================= Write-Verbose "[$(Get-Date -format G)] [$($MyInvocation.MyCommand.Name)] Start" $Error.Clear() #Write-Host -ForegroundColor DarkCyan "[$(Get-Date -format G)] [$($MyInvocation.MyCommand.Name)] Start" $IsAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) if (-not $IsAdmin ) { Write-Warning "[$(Get-Date -format G)] [$($MyInvocation.MyCommand.Name)] must be run with Administrator privileges" Break } #================================================= Write-Verbose "[$(Get-Date -format G)] [$($MyInvocation.MyCommand.Name)] Building PSDrive array containing Windows Media, including Mounted ISOs" $WindowsMediaDrives = @() $WindowsMediaDrives = Get-PSDrive -PSProvider 'FileSystem' | ` Where-Object { ($_.Name).Length -eq 1 } | ` Where-Object { $_.Name -match '^[D-Z]' } | ` Where-Object { $_.Root -match '^[D-Z]:\\' } Write-Verbose "[$(Get-Date -format G)] [$($MyInvocation.MyCommand.Name)] Found $($WindowsMediaDrives.Count) PSDrives containing Windows Media" $WindowsMediaSources = @() foreach ($Drive in $WindowsMediaDrives) { if (Test-Path "$($Drive.Root)Sources") { Write-Verbose "[$(Get-Date -format G)] [$($MyInvocation.MyCommand.Name)] Gathering WindowsImage information from $($Drive.Root)Sources" $WindowsMediaSources += Get-ChildItem "$($Drive.Root)Sources\*" -Include boot.wim -ErrorAction SilentlyContinue | ` Select-Object -Property @{Name = 'MediaRoot'; Expression = { (Get-Item $_.Directory).Parent.FullName } }, * } if (Test-Path "$($Drive.Root)x64\Sources") { Write-Verbose "[$(Get-Date -format G)] [$($MyInvocation.MyCommand.Name)] Gathering WindowsImage information from $($Drive.Root)x64\Sources" $WindowsMediaSources += Get-ChildItem "$($Drive.Root)x64\Sources\*" -Include boot.wim -ErrorAction SilentlyContinue | ` Select-Object -Property @{Name = 'MediaRoot'; Expression = { (Get-Item $_.Directory).Parent.FullName } }, * } if (Test-Path "$($Drive.Root)x86\Sources") { Write-Verbose "[$(Get-Date -format G)] [$($MyInvocation.MyCommand.Name)] Gathering WindowsImage information from $($Drive.Root)x86\Sources" $WindowsMediaSources += Get-ChildItem "$($Drive.Root)x86\Sources\*" -Include boot.wim -ErrorAction SilentlyContinue | ` Select-Object -Property @{Name = 'MediaRoot'; Expression = { (Get-Item $_.Directory).Parent.FullName } }, * } } if ($WindowsMediaSources) { Write-Verbose "[$(Get-Date -format G)] [$($MyInvocation.MyCommand.Name)] Returning System.IO.FileSystemInfo object" return $WindowsMediaSources } else { Write-Verbose "[$(Get-Date -format G)] [$($MyInvocation.MyCommand.Name)] No Windows Media found" return $null } #================================================= Write-Verbose "[$(Get-Date -format G)] [$($MyInvocation.MyCommand.Name)] End" #================================================= } |