Skip to content

Commit

Permalink
Update MDT functions
Browse files Browse the repository at this point in the history
Update try//catch, change supported platforms for fix detection on Windows 11
  • Loading branch information
aaronparker committed Oct 3, 2023
1 parent b21d58e commit 02655f1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 30 deletions.
19 changes: 12 additions & 7 deletions VcRedist/Private/Import-MdtModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
34 changes: 13 additions & 21 deletions VcRedist/Private/New-MdtDrive.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions VcRedist/Public/Import-VcMdtApplication.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 02655f1

Please sign in to comment.