Skip to content

Commit

Permalink
Fix Update-VcMdtApplication
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronparker committed Nov 9, 2022
1 parent 42dd636 commit 0098894
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 116 deletions.
14 changes: 7 additions & 7 deletions VcRedist/Private/Import-MdtModule.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Function Import-MdtModule {
function Import-MdtModule {
<#
.SYNOPSIS
Tests for and imports the MDT PowerShell module. Returns True or False depending on whether the module can be loaded.
Expand All @@ -12,7 +12,7 @@ Function Import-MdtModule {
#>
[CmdletBinding()]
[OutputType([System.Boolean])]
Param (
param (
[Parameter(Mandatory = $False)]
[System.Management.Automation.SwitchParameter] $Force
)
Expand All @@ -23,32 +23,32 @@ Function Import-MdtModule {
}
catch [System.Exception] {
Write-Warning "$($MyInvocation.MyCommand): Unable to read MDT Registry path properties."
Throw $_.Exception.Message
throw $_.Exception.Message
}

# Attempt to load the module
$mdtInstallDir = Resolve-Path -Path $mdtReg.Install_Dir
$mdtModule = [System.IO.Path]::Combine($mdtInstallDir, "bin", "MicrosoftDeploymentToolkit.psd1")
If (Test-Path -Path $mdtModule -ErrorAction "SilentlyContinue") {
if (Test-Path -Path $mdtModule -ErrorAction "SilentlyContinue") {
Write-Verbose "$($MyInvocation.MyCommand): Loading MDT module from: [$mdtInstallDir]."
try {
$params = @{
Name = $mdtModule
ErrorAction = "SilentlyContinue"
Force = If ($Force) { $True } Else { $False }
Force = if ($Force) { $True } else { $False }
}
Import-Module @params
}
catch [System.Exception] {
Write-Output -InputObject $False
Write-Warning "$($MyInvocation.MyCommand): Could not load MDT PowerShell Module. Please make sure that the MDT console is installed correctly."
Throw $_.Exception.Message
throw $_.Exception.Message
}
finally {
Write-Output -InputObject $True
}
}
Else {
else {
Write-Warning "$($MyInvocation.MyCommand): Cannot find the MDT PowerShell module. Is the MDT console installed?"
Write-Output -InputObject $False
}
Expand Down
14 changes: 7 additions & 7 deletions VcRedist/Private/New-MdtDrive.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Function New-MdtDrive {
function New-MdtDrive {
<#
.SYNOPSIS
Creates a new persistent PS drive mapped to an MDT share.
Expand All @@ -15,31 +15,31 @@ Function New-MdtDrive {
#>
[CmdletBinding(SupportsShouldProcess)]
[OutputType([System.String])]
Param (
param (
[Parameter(Mandatory = $False, Position = 0)]
[ValidateNotNullOrEmpty()]
[System.String] $Drive = "DS009",
[System.String] $Drive = "DS099",

[Parameter(Mandatory = $True, Position = 1)]
[ValidateNotNullOrEmpty()]
[System.String] $Path
)
$description = "MDT drive created by $($MyInvocation.MyCommand)"

If ($mdtDrives = Get-MdtPersistentDrive | Where-Object { ($_.Path -eq $Path) -and ($_.Description -eq $Description) }) {
if ($mdtDrives = Get-MdtPersistentDrive | Where-Object { ($_.Path -eq $Path) -and ($_.Description -eq $Description) }) {
Write-Verbose "$($MyInvocation.MyCommand): Found MDT drive: $($mdtDrives[0].Name)"
$output = $mdtDrives[0].Name
}
Else {
If ($PSCmdlet.ShouldProcess("$($Drive): to $($Path)", "Mapping")) {
else {
if ($PSCmdlet.ShouldProcess("$($Drive): to $($Path)", "Mapping")) {
try {
New-PSDrive -Name $Drive -PSProvider "MDTProvider" -Root $Path `
-NetworkPath $Path -Description $description | Add-MDTPersistentDrive
$psDrive = Get-MdtPersistentDrive | Where-Object { ($_.Path -eq $Path) -and ($_.Name -eq $Drive) }
}
catch [System.Exception] {
Write-Warning -Message "$($MyInvocation.MyCommand): Failed to create MDT drive at: [$Path]."
Throw $_.Exception.Message
throw $_.Exception.Message
}
finally {
Write-Verbose "$($MyInvocation.MyCommand): Found: $($psDrive.Name)"
Expand Down
8 changes: 4 additions & 4 deletions VcRedist/Public/Import-VcIntuneApplication.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function Import-VcIntuneApplication {
}

# Test for authentication token
if ($Null -eq $Global:AccessToken) {
if ($null -eq $Global:AccessToken) {
throw "Microsoft Graph API access token missing. Authenticate to the Graph API with Connect-MSIntuneGraph."
}

Expand Down Expand Up @@ -73,9 +73,9 @@ function Import-VcIntuneApplication {
# Requirement rule
if ($VcRedist.Architecture -eq "x86") { $Architecture = "All" } else { $Architecture = "x64" }
$params = @{
Architecture = $Architecture
MinimumSupportedOperatingSystem = $IntuneManifest.RequirementRule.MinimumRequiredOperatingSystem
MinimumFreeDiskSpaceInMB = $IntuneManifest.RequirementRule.SizeInMBValue
Architecture = $Architecture
MinimumSupportedWindowsRelease = $IntuneManifest.RequirementRule.MinimumRequiredOperatingSystem
MinimumFreeDiskSpaceInMB = $IntuneManifest.RequirementRule.SizeInMBValue
}
$RequirementRule = New-IntuneWin32AppRequirementRule @params

Expand Down
2 changes: 1 addition & 1 deletion VcRedist/Public/Import-VcMdtApplication.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Function Import-VcMdtApplication {

[Parameter(Mandatory = $False, Position = 4)]
[ValidatePattern('^[a-zA-Z0-9]+$')]
[System.String] $MdtDrive = "DS001",
[System.String] $MdtDrive = "DS099",

[Parameter(Mandatory = $False, Position = 5)]
[ValidatePattern('^[a-zA-Z0-9]+$')]
Expand Down
2 changes: 1 addition & 1 deletion VcRedist/Public/New-VcMdtBundle.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Function New-VcMdtBundle {

[Parameter(Mandatory = $False, Position = 2)]
[ValidatePattern('^[a-zA-Z0-9]+$')]
[System.String] $MdtDrive = "DS001",
[System.String] $MdtDrive = "DS099",

[Parameter(Mandatory = $False, Position = 3)]
[ValidatePattern('^[a-zA-Z0-9]+$')]
Expand Down
Loading

0 comments on commit 0098894

Please sign in to comment.