Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Several new features #23

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Scripts/Install-Modules.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Process {
# Ensure package provider is installed
$PackageProvider = Install-PackageProvider -Name "NuGet" -Force

$Modules = @("Evergreen", "IntuneWin32App", "Az.Storage", "Az.Resources", "MSGraphRequest")
$Modules = @("Evergreen", "IntuneWin32App", "Az.Storage", "Az.Resources")
foreach ($Module in $Modules) {
try {
Write-Output -InputObject "Attempting to locate module: $($Module)"
Expand All @@ -46,7 +46,7 @@ Process {
}
else {
Write-Output -InputObject "Attempting to install module: $($Module)"
$InstallModuleInvocation = Install-Module -Name $Module -Force -AllowClobber -ErrorAction "Stop" -Confirm:$false -Verbose:$false
$InstallModuleInvocation = Install-Module -Name $Module -Force -ErrorAction "Stop" -Confirm:$false -Verbose:$false
Write-Output -InputObject "Module $($Module) installed successfully"
}
}
Expand Down
25 changes: 19 additions & 6 deletions Scripts/New-AppAssignment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,38 @@
#>
[CmdletBinding(SupportsShouldProcess = $true)]
param (
[parameter(Mandatory = $true)]
[parameter(Mandatory = $true, ParameterSetName = "ClientSecret")]
[parameter(Mandatory = $true, ParameterSetName = "ClientCertificate")]
[ValidateNotNullOrEmpty()]
[string]$TenantID,

[parameter(Mandatory = $true)]
[parameter(Mandatory = $true, ParameterSetName = "ClientSecret")]
[parameter(Mandatory = $true, ParameterSetName = "ClientCertificate")]
[ValidateNotNullOrEmpty()]
[string]$ClientID,

[parameter(Mandatory = $true)]
[parameter(Mandatory = $true, ParameterSetName = "ClientSecret")]
[ValidateNotNullOrEmpty()]
[string]$ClientSecret
[string]$ClientSecret,

[parameter(Mandatory = $true, ParameterSetName = "ClientCertificate")]
[ValidateNotNullOrEmpty()]
[System.Security.Cryptography.X509Certificates.X509Certificate2]$ClientCertificate
)
Process {
# Construct path for AppsAssignList.json file created in previous stage
$AppsAssignListFileName = "AppsAssignList.json"
$AppsAssignListFilePath = Join-Path -Path (Join-Path -Path $env:BUILD_ARTIFACTSTAGINGDIRECTORY -ChildPath "AppsPublishedList") -ChildPath $AppsAssignListFileName

# Retrieve authentication token using client secret from key vault
$AuthToken = Connect-MSIntuneGraph -TenantID $TenantID -ClientID $ClientID -ClientSecret $ClientSecret -ErrorAction "Stop"
# Retrieve authentication token using client secret from key vault or client certificate
switch ($PSCmdlet.ParameterSetName) {
"ClientSecret" {
$AuthToken = Connect-MSIntuneGraph -TenantID $TenantID -ClientID $ClientID -ClientSecret $ClientSecret -ErrorAction "Stop"
}
"ClientCertificate" {
$AuthToken = Connect-MSIntuneGraph -TenantID $TenantID -ClientID $ClientID -ClientCert $ClientCertificate -ErrorAction "Stop"
}
}

if (Test-Path -Path $AppsAssignListFilePath) {
# Read content from AppsAssignList.json file and convert from JSON format
Expand Down
29 changes: 22 additions & 7 deletions Scripts/New-Win32App.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,31 @@
#>
[CmdletBinding(SupportsShouldProcess = $true)]
param (
[parameter(Mandatory = $true)]
[parameter(Mandatory = $true, ParameterSetName = "ClientSecret")]
[parameter(Mandatory = $true, ParameterSetName = "ClientCertificate")]
[ValidateNotNullOrEmpty()]
[string]$TenantID,

[parameter(Mandatory = $true)]
[parameter(Mandatory = $true, ParameterSetName = "ClientSecret")]
[parameter(Mandatory = $true, ParameterSetName = "ClientCertificate")]
[ValidateNotNullOrEmpty()]
[string]$ClientID,

[parameter(Mandatory = $true)]
[parameter(Mandatory = $true, ParameterSetName = "ClientSecret")]
[ValidateNotNullOrEmpty()]
[string]$ClientSecret,

[parameter(Mandatory = $true)]
[parameter(Mandatory = $true, ParameterSetName = "ClientCertificate")]
[ValidateNotNullOrEmpty()]
[System.Security.Cryptography.X509Certificates.X509Certificate2]$ClientCertificate,

[parameter(Mandatory = $true, ParameterSetName = "ClientSecret")]
[parameter(Mandatory = $true, ParameterSetName = "ClientCertificate")]
[ValidateNotNullOrEmpty()]
[string]$WorkspaceID,

[parameter(Mandatory = $true)]
[parameter(Mandatory = $true, ParameterSetName = "ClientSecret")]
[parameter(Mandatory = $true, ParameterSetName = "ClientCertificate")]
[ValidateNotNullOrEmpty()]
[string]$SharedKey
)
Expand Down Expand Up @@ -150,8 +158,15 @@ Process {
$AppsPublishListFileName = "AppsPublishList.json"
$AppsPublishListFilePath = Join-Path -Path (Join-Path -Path $env:BUILD_ARTIFACTSTAGINGDIRECTORY -ChildPath "AppsPublishList") -ChildPath $AppsPublishListFileName

# Retrieve authentication token using client secret from key vault
$AuthToken = Connect-MSIntuneGraph -TenantID $TenantID -ClientID $ClientID -ClientSecret $ClientSecret -ErrorAction "Stop"
# Retrieve authentication token using client secret from key vault or client certificate
switch ($PSCmdlet.ParameterSetName) {
"ClientSecret" {
$AuthToken = Connect-MSIntuneGraph -TenantID $TenantID -ClientID $ClientID -ClientSecret $ClientSecret -ErrorAction "Stop"
}
"ClientCertificate" {
$AuthToken = Connect-MSIntuneGraph -TenantID $TenantID -ClientID $ClientID -ClientCert $ClientCertificate -ErrorAction "Stop"
}
}

if (Test-Path -Path $AppsPublishListFilePath) {
# Read content from AppsPublishList.json file and convert from JSON format
Expand Down
55 changes: 45 additions & 10 deletions Scripts/Prepare-AppPackageFolder.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,36 @@ Process {
Copy-Item -Path "$($FrameworkPath)\*" -Destination $AppPublishFolderPath -Recurse -Force -Confirm:$false

# Create Files folder in Source folder if not found
$AppsPublishSourceFilesPath = Join-Path -Path $AppsPublishRootPath -ChildPath "$($App.AppFolderName)\Source\Files"
if (-not(Test-Path -Path $AppsPublishSourceFilesPath)) {
New-Item -Path $AppsPublishSourceFilesPath -ItemType "Directory" -Force -Confirm:$false | Out-Null
$AppPublishSourceFilesPath = Join-Path -Path $AppPublishFolderPath -ChildPath "Source\Files"
if (-not(Test-Path -Path $AppPublishSourceFilesPath)) {
New-Item -Path $AppPublishSourceFilesPath -ItemType "Directory" -Force -Confirm:$false | Out-Null
}

# Copy app specific installer from downloaded app package path to publish folder
$AppInstallerPath = Join-Path -Path $App.AppSetupFolderPath -ChildPath $App.AppSetupFileName
$AppInstallerDestinationPath = Join-Path -Path $AppPublishFolderPath -ChildPath "Source\Files\$($App.AppSetupFileName)"
$AppInstallerDestinationPath = Join-Path -Path $AppPublishSourceFilesPath -ChildPath $App.AppSetupFileName
Write-Output -InputObject "Copying installer file from app package download folder"
Write-Output -InputObject "Source path: $($AppInstallerPath)"
Write-Output -InputObject "Destination path: $($AppInstallerDestinationPath)"
Copy-Item -Path $AppInstallerPath -Destination $AppInstallerDestinationPath -Force -Confirm:$false

# Copy all required app specific files from app package folder in Apps root folder to publish folder
$AppPackageFolderPath = Join-Path -Path $SourceDirectory -ChildPath "Apps\$($App.AppFolderName)"
$AppFileNames = $AppFileNames = @("App.json", "Deploy-Application.ps1", "Icon.png")

# Copy SupportFiles folder from app package folder in Apps root to Source folder if it exists and is not empty
$AppSupportFilesPath = Join-Path -Path $AppPackageFolderPath -ChildPath "SupportFiles"
if (Test-Path -Path "$AppSupportFilesPath\*") {
Copy-Item -Path $AppSupportFilesPath -Destination "$AppPublishFolderPath\Source" -Container -Recurse -Force -Confirm:$false
}

# Read app specific App.json manifest and convert from JSON
$AppDataFile = Join-Path -Path $AppPackageFolderPath -ChildPath "App.json"
$AppData = Get-Content -Path $AppDataFile | ConvertFrom-Json

# Get app icon file name
$IconFileName = if (-not([string]::IsNullOrEmpty($AppData.PackageInformation.IconFile))) { $AppData.PackageInformation.IconFile } else { "Icon.png" }

$AppFileNames = $AppFileNames = @("App.json", "Deploy-Application.ps1", $IconFileName)
foreach ($AppFileName in $AppFileNames) {
Write-Output -InputObject "[FILE: $($AppFileName)] - Processing"

Expand All @@ -102,7 +116,25 @@ Process {
Write-Output -InputObject "Setting timestamp to: $((Get-Date).ToShortDateString())"
$AppFileContent = $AppFileContent -replace "###DATETIME###", (Get-Date).ToShortDateString()
Write-Output -InputObject "Setting setup file name to: $($App.AppSetupFileName)"
$AppFileContent = $AppFileContent -replace "###SETUPFILENAME###", $($App.AppSetupFileName)
$AppFileContent = $AppFileContent -replace "###SETUPFILENAME###", $App.AppSetupFileName
Write-Output -InputObject "Setting PSADT pre-install section to: $($AppData.PSADT.PreInstallSection)"
$AppFileContent = $AppFileContent -replace "###PREINSTALLSECTION###", $AppData.PSADT.PreInstallSection
Write-Output -InputObject "Setting PSADT install section to: $($AppData.PSADT.InstallSection)"
$AppFileContent = $AppFileContent -replace "###INSTALLSECTION###", $AppData.PSADT.InstallSection
Write-Output -InputObject "Setting PSADT post-install section to: $($AppData.PSADT.PostInstallSection)"
$AppFileContent = $AppFileContent -replace "###POSTINSTALLSECTION###", $AppData.PSADT.PostInstallSection
Write-Output -InputObject "Setting PSADT pre-uninstall section to: $($AppData.PSADT.PreUninstallSection)"
$AppFileContent = $AppFileContent -replace "###PREUNINSTALLSECTION###", $AppData.PSADT.PreUninstallSection
Write-Output -InputObject "Setting PSADT uninstall section to: $($AppData.PSADT.UninstallSection)"
$AppFileContent = $AppFileContent -replace "###UNINSTALLSECTION###", $AppData.PSADT.UninstallSection
Write-Output -InputObject "Setting PSADT post-uninstall section to: $($AppData.PSADT.PostUninstallSection)"
$AppFileContent = $AppFileContent -replace "###POSTUNINSTALLSECTION###", $AppData.PSADT.PostUninstallSection
Write-Output -InputObject "Setting PSADT pre-repair section to: $($AppData.PSADT.PreRepairSection)"
$AppFileContent = $AppFileContent -replace "###PREREPAIRSECTION###", $AppData.PSADT.PreRepairSection
Write-Output -InputObject "Setting PSADT repair section to: $($AppData.PSADT.RepairSection)"
$AppFileContent = $AppFileContent -replace "###REPAIRSECTION###", $AppData.PSADT.RepairSection
Write-Output -InputObject "Setting PSADT post-repair section to: $($AppData.PSADT.PostRepairSection)"
$AppFileContent = $AppFileContent -replace "###POSTREPAIRSECTION###", $AppData.PSADT.PostRepairSection

# Read and update hardcoded variables with specific MSI data from setup file if file extension is MSI
$SetupFileNameExtension = [System.IO.Path]::GetExtension($App.AppSetupFileName).Trim(".")
Expand All @@ -128,6 +160,12 @@ Process {
Write-Output -InputObject "File path: $($AppFilePath)"
$AppFileContent = Get-Content -Path $AppFilePath | ConvertFrom-Json

# Add timestamp to Notes property
if ($AppFileContent.Information.Notes -match "(\#{3})DATETIME(\#{3})") {
Write-Output -InputObject "Setting Notes timestamp to: $(Get-Date -Format yyyy-MM-dd)"
$AppFileContent.Information.Notes = $AppFileContent.Information.Notes -replace "###DATETIME###", (Get-Date -Format yyyy-MM-dd)
}

# Update version specific property values
$AppFileContent.Information.DisplayName = $App.IntuneAppName
$AppFileContent.Information.AppVersion = $App.AppSetupVersion
Expand Down Expand Up @@ -255,7 +293,7 @@ Process {
Write-Output -InputObject "Creating '$($AppFileName)' in: $($AppFileDestinationPath)"
Out-File -InputObject ($AppFileContent | ConvertTo-Json) -FilePath $AppFileDestinationPath -Encoding "utf8" -Force -Confirm:$false
}
"Icon.png" {
$IconFileName {
# If IconURL attribute is present for current app item, download icon from URL to the app package folder in the publish root folder
if (-not([string]::IsNullOrEmpty($App.IconURL))) {
Write-Output -InputObject "Downloading icon file from URL: $($App.IconURL)"
Expand All @@ -271,9 +309,6 @@ Process {
Write-Output -InputObject "Destination path: $($AppFileDestinationPath)"
Copy-Item -Path $AppFilePath -Destination $AppFileDestinationPath -Force -Confirm:$false
}

# Declare the icon file name to set in the current app item attribute for IconFileName
$IconFileName = $AppFileName
}
}

Expand Down
19 changes: 11 additions & 8 deletions Scripts/Test-AppFiles.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -101,26 +101,28 @@ Process {
}
}
else {
Write-Warning -Message "Icon URL was defined but value was empty, checking for local Icon.png file"
$IconFilePath = Join-Path -Path $AppPackageFolderPath -ChildPath "Icon.png"
$IconFile = $AppFileContent.PackageInformation.IconFile
Write-Warning -Message "Icon URL was defined but value was empty, checking for local $IconFile file"
$IconFilePath = Join-Path -Path $AppPackageFolderPath -ChildPath $IconFile
if (-not(Test-Path -Path $IconFilePath)) {
Write-Warning -Message "Could not detect local Icon.png file in app folder"
Write-Warning -Message "Could not detect local $IconFile file in app folder"
$AppAllowed = $false
}
else {
Write-Output -InputObject "Found local Icon.png file in app folder"
Write-Output -InputObject "Found local $IconFile file in app folder"
}
}
}
else {
Write-Output -InputObject "Icon URL was not defined, testing for local Icon.png file"
$IconFilePath = Join-Path -Path $AppPackageFolderPath -ChildPath "Icon.png"
$IconFile = $AppFileContent.PackageInformation.IconFile
Write-Output -InputObject "Icon URL was not defined, testing for local $IconFile file"
$IconFilePath = Join-Path -Path $AppPackageFolderPath -ChildPath $IconFile
if (-not(Test-Path -Path $IconFilePath)) {
Write-Warning -Message "Could not detect local Icon.png file in app folder"
Write-Warning -Message "Could not detect local $IconFile file in app folder"
$AppAllowed = $false
}
else {
Write-Output -InputObject "Found local Icon.png file in app folder"
Write-Output -InputObject "Found local $IconFile file in app folder"
}
}

Expand Down Expand Up @@ -166,6 +168,7 @@ Process {
"AppSource" = $App.AppSource
"AppId" = if (-not([string]::IsNullOrEmpty($App.AppId))) { $App.AppId } else { [string]::Empty }
"AppFolderName" = $App.AppFolderName
"AppSetupFileName" = $App.AppSetupFileName
"FilterOptions" = $App.FilterOptions
"StorageAccountName" = if (-not([string]::IsNullOrEmpty($App.StorageAccountName))) { $App.StorageAccountName } else { [string]::Empty }
"StorageAccountContainerName" = if (-not([string]::IsNullOrEmpty($App.StorageAccountContainerName))) { $App.StorageAccountContainerName } else { [string]::Empty }
Expand Down
Loading