Djentacodic

New-IntuneWin.ps1

Apr 12th, 2024 (edited)
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PowerShell 1.45 KB | Source Code | 0 0
  1. [CmdletBinding()]
  2. Param(
  3.     [Parameter(Mandatory=$true)]
  4.     [ArgumentCompleter({
  5.         param($cmd, $param, $wordToComplete)
  6.         [array]$ItemList = (Get-ChildItem -Path $global:IntunePackages -Directory | Where-Object {$_.Name -inotmatch "^\d{1,2}-"}).Name
  7.         $ItemList -ilike "$wordToComplete*"
  8.     })]
  9.     [ValidateScript({
  10.         if (Test-Path -Path "$global:IntunePackages\$_" -PathType Container) {
  11.             $_ -inotmatch "^\d{1,2}-"
  12.         }
  13.         else {
  14.             $false
  15.         }
  16.     })]
  17.     [String]$PackageName,
  18.     [Switch]$Force
  19. )
  20.  
  21. [String]$Source = "$global:IntunePackages\$PackageName"
  22. [String]$Script = ''
  23. [String]$Output = $global:IntunePackagePath
  24. [String[]]$Params = @()
  25.  
  26. if ((Get-ChildItem -Path "${Source}\*" -Include "Deploy-Application.*","ServiceUI.exe" | Measure-Object).Count -eq 4) {
  27.  
  28.     $Script = Get-ChildItem -Path "${Source}\*" -Filter "*.ps1" -Exclude "Deploy-Application.ps1" | Select-Object -ExpandProperty 'Name' -First 1
  29.     if (!($Script)) {
  30.         Write-Error "'$Source' is missing critical files.`nMake sure all necessary files are in the project folder."
  31.         Remove-Variable PackagePath,Force,Source,Script,Output,Params
  32.         return
  33.     }
  34.  
  35.     $Params = @('-c',"$Source",'-s',"$Script",'-o',"$Output")
  36.  
  37.     if ($Force) {
  38.         $Params += "-q"
  39.     }
  40.  
  41.     & $global:IntunePackages\IntuneWinAppUtil.exe $Params
  42. }
  43. else {
  44.     Write-Error "'$Source' is missing critical files.`nMake sure all necessary files are in the project folder."
  45. }
  46.  
  47. Remove-Variable PackageName,Force,Source,Script,Output,Params -Force
Add Comment
Please, Sign In to add comment