|
| 1 | +param( |
| 2 | + [Parameter(Mandatory = $true)] |
| 3 | + [string]$SourcePath, |
| 4 | + [Parameter(Mandatory = $true)] |
| 5 | + [string]$FileName, |
| 6 | + [Parameter(Mandatory = $true)] |
| 7 | + [string]$MetadataFileName |
| 8 | +) |
| 9 | + |
| 10 | +# Example: .\Tools\IntuneWin\New-IntuneWinPackage.ps1 -SourcePath .\AddMSPApp\datto\ -FileName datto.intunewin -MetadataFileName datto.app.xml |
| 11 | + |
| 12 | +$Source = Get-Item -Path $SourcePath |
| 13 | + |
| 14 | +$Params = @( |
| 15 | + "-c $SourcePath" |
| 16 | + '-s install.ps1' |
| 17 | + "-o $SourcePath" |
| 18 | + '-q' |
| 19 | +) |
| 20 | + |
| 21 | +Start-Process -FilePath "$PSScriptRoot\IntuneWinAppUtil.exe" -ArgumentList $Params -Wait -NoNewWindow |
| 22 | + |
| 23 | +Expand-Archive -Path "$SourcePath\install.intunewin" -DestinationPath $SourcePath -Force |
| 24 | +Write-Host "IntuneWin package contents extracted to: $SourcePath" |
| 25 | +Remove-Item -Path "$SourcePath\install.intunewin" -Force |
| 26 | +Write-Host "Temporary IntuneWin package file removed from: $SourcePath\install.intunewin" |
| 27 | + |
| 28 | +# Extract IntunePackage.intunewin from Contents and move to the parent directory |
| 29 | +$IntunePackagePath = Join-Path $SourcePath 'IntuneWinPackage\Contents\IntunePackage.intunewin' |
| 30 | +if (Test-Path -Path $IntunePackagePath) { |
| 31 | + Move-Item -Path $IntunePackagePath -Destination (Join-Path $Source.Parent.FullName $FileName) -Force |
| 32 | + Write-Host "IntunePackage.intunewin moved to: $($Source.Parent.FullName)\$FileName" |
| 33 | +} else { |
| 34 | + Write-Host 'IntunePackage.intunewin not found in Contents directory.' |
| 35 | +} |
| 36 | + |
| 37 | +# Copy the Metadata/Detection.xml file to the parent directory |
| 38 | +$DetectionFilePath = Join-Path $SourcePath 'IntuneWinPackage\Metadata\Detection.xml' |
| 39 | + |
| 40 | +if (Test-Path -Path $DetectionFilePath) { |
| 41 | + $MetadataXml = [xml](Get-Content -Path $DetectionFilePath) |
| 42 | + $MetadataXml.ApplicationInfo.FileName = $FileName |
| 43 | + $MetadataXml.Save($DetectionFilePath) |
| 44 | + Write-Host "Detection.xml updated with FileName: $FileName" |
| 45 | +} else { |
| 46 | + Write-Host 'Detection.xml not found in Metadata directory.' |
| 47 | +} |
| 48 | + |
| 49 | +if (Test-Path -Path $DetectionFilePath) { |
| 50 | + Copy-Item -Path $DetectionFilePath -Destination (Join-Path $Source.Parent.FullName $MetadataFileName) -Force |
| 51 | + Write-Host "Detection.xml copied to: $($Source.Parent.FullName)\$MetadataFileName" |
| 52 | +} else { |
| 53 | + Write-Host 'Detection.xml not found in Metadata directory.' |
| 54 | +} |
| 55 | + |
| 56 | +# Clean up the Source directory |
| 57 | +Remove-Item -Path $SourcePath -Recurse -Force |
| 58 | +Write-Host "Temporary files cleaned up from: $SourcePath" |
0 commit comments