From 02655f198a02e5787e59ac884f1d4488cfac3386 Mon Sep 17 00:00:00 2001 From: Aaron Parker Date: Tue, 3 Oct 2023 20:55:41 +1100 Subject: [PATCH] Update MDT functions Update try//catch, change supported platforms for fix detection on Windows 11 --- VcRedist/Private/Import-MdtModule.ps1 | 19 +++++++----- VcRedist/Private/New-MdtDrive.ps1 | 34 ++++++++------------- VcRedist/Public/Import-VcMdtApplication.ps1 | 4 +-- 3 files changed, 27 insertions(+), 30 deletions(-) diff --git a/VcRedist/Private/Import-MdtModule.ps1 b/VcRedist/Private/Import-MdtModule.ps1 index 8c3a4c73..a4235e2c 100644 --- a/VcRedist/Private/Import-MdtModule.ps1 +++ b/VcRedist/Private/Import-MdtModule.ps1 @@ -32,14 +32,19 @@ function Import-MdtModule { $MdtInstallDir = Resolve-Path -Path $MdtReg.Install_Dir $MdtModule = [System.IO.Path]::Combine($MdtInstallDir, "bin", "MicrosoftDeploymentToolkit.psd1") if (Test-Path -Path $mdtModule -ErrorAction "SilentlyContinue") { - Write-Verbose -Message "Loading MDT module from: $MdtInstallDir." - $params = @{ - Name = $MdtModule - ErrorAction = "Stop" - Force = if ($Force) { $true } else { $false } + try { + Write-Verbose -Message "Loading MDT module from: $MdtInstallDir." + $params = @{ + Name = $MdtModule + ErrorAction = "Stop" + Force = if ($Force) { $true } else { $false } + } + Import-Module @params + Write-Output -InputObject $true + } + catch { + throw $_ } - Import-Module @params - Write-Output -InputObject $true } else { $Msg = "Unable to find the MDT PowerShell module at $MdtModule. Ensure the Microsoft Deployment Toolkit is installed and try again." diff --git a/VcRedist/Private/New-MdtDrive.ps1 b/VcRedist/Private/New-MdtDrive.ps1 index c8499dc6..ce51bf34 100644 --- a/VcRedist/Private/New-MdtDrive.ps1 +++ b/VcRedist/Private/New-MdtDrive.ps1 @@ -28,27 +28,19 @@ function New-MdtDrive { # Set a description to be applied to the new MDT drive $Description = "MDT drive created by $($MyInvocation.MyCommand)" - if ($mdtDrives = Get-MdtPersistentDrive | Where-Object { ($_.Path -eq $Path) -and ($_.Description -eq $Description) }) { - Write-Verbose -Message "Found MDT drive: $($mdtDrives[0].Name)" - $output = $mdtDrives[0].Name - } - else { - if ($PSCmdlet.ShouldProcess("$($Drive): to $($Path)", "Mapping")) { - $params = @{ - Name = $Drive - PSProvider = "MDTProvider" - Root = $Path - #NetworkPath = $Path - Description = $Description - ErrorAction = "Stop" - } - New-PSDrive @params | Add-MDTPersistentDrive - - # Return the MDT drive name - $psDrive = Get-MdtPersistentDrive | Where-Object { $_.Path -eq $Path -and $_.Name -eq $Drive } - Write-Verbose -Message "Found: $($psDrive.Name)" - $output = $psDrive.Name + if ($PSCmdlet.ShouldProcess("$($Drive): to $($Path)", "Mapping")) { + $params = @{ + Name = $Drive + PSProvider = "MDTProvider" + Root = $Path + Description = $Description + ErrorAction = "Stop" } + New-PSDrive @params | Add-MDTPersistentDrive + + # Return the MDT drive name + $psDrive = Get-MdtPersistentDrive | Where-Object { $_.Path -eq $Path -and $_.Name -eq $Drive } + Write-Verbose -Message "Found: $($psDrive.Name)" + Write-Output -InputObject $psDrive.Name } - Write-Output -InputObject $output } diff --git a/VcRedist/Public/Import-VcMdtApplication.ps1 b/VcRedist/Public/Import-VcMdtApplication.ps1 index 685f1a87..62572d65 100644 --- a/VcRedist/Public/Import-VcMdtApplication.ps1 +++ b/VcRedist/Public/Import-VcMdtApplication.ps1 @@ -118,10 +118,10 @@ function Import-VcMdtApplication { # Set variables Write-Verbose -Message "processing: '$($VcRedist.Name) $($VcRedist.Architecture)'." $supportedPlatform = if ($VcRedist.Architecture -eq "x86") { - @("All x86 Windows 7 and Newer", "All x64 Windows 7 and Newer") + $null } else { - @("All x64 Windows 7 and Newer") + @("All x64 Windows 10 Client", "All x64 Windows Server 10") } # Check for existing application by matching current VcRedist