The PowerShell Win32 App Express

The PowerShell Win32 App Express

In my last blog I expressed my opinion about how important it is to use the company portal to distribute apps. 

Like I was mentioning, it can be a lot of work when you need to create all these apps each time a customer asks for one.  Of course, you can create one Chocolatey app which simply installs every app. But I prefer to give the user a nice dashboard with all the possible apps he or she can install. 

You will need to automate this somehow otherwise it can take a lot of time. 

There are some steps you need to take to automate it: 

  1. Create the app itself. 
  1. Convert the apps to intunewin apps. 
  1. Upload the apps to Intune. 
  1. Configure the assignments. 
  1. Add the logo…. 

Before we can begin, make sure you download the files required. 

1: GitHub – microsoft/Microsoft-Win32-Content-Prep-Tool: A tool to wrap Win32 App and then it can be uploaded to Intune 

2: powershell-intune-samples/LOB_Application at master · microsoftgraph/powershell-intune-samples · GitHub 

3: powershell-intune-samples/Application_Get_Assign.ps1 at master · microsoftgraph/powershell-intune-samples · GitHub 

4: Download Fiddler Web Debugging Tool for Free by Telerik 

Step 1:  

The first thing you will need to do is create a folder where you are going to store these apps. In the example below I created multiple folders c:\packages\chocolateyappsinstall\*APPNAME* 

Inside the folder I created the install.ps1, uninstall.ps1 and the logo jpg file (you will need to do this one time to get some information about it).  

Content install.ps1 

if (!(Test-Path -Path "$env:ProgramData\Chocolatey")) { 
  Invoke-Expression((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) 
} 
$ChocoPackages = @("jre8") 
$chocoinstall = Get-Command -Name 'choco' -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Select-Object -ExpandProperty Source 
foreach($Package in $ChocoPackages) { 
     try { 
         Invoke-Expression “cmd.exe /c $ChocoInstall Install $Package -y” -ErrorAction Stop 
     } 
     catch { 
         Throw “Failed to install $Package” 
     } 
} 

Content uninstall.ps1 

choco uninstall jre8 -y 

You can do this for every app (just change the chocopackage you need) 

Now we just need to create the intunewinapp for each app. That’s step 1, so let’s create the app with the Microsoft Win32 Content Prep tool.  


Step2:  

When you have created the intunewin apps we can move to step 2: Pushing the app to Intune. You will need the Win32_application_add.ps1 you downloaded earlier. 

Add all apps to the script you created (please be aware of the detection rules, they are quite important). Also, please make sure the source file corresponds with the intunewinapp you have created. Here is an example for Java. 

Step2:  

When you have created the intunewin apps we can move to step 2: Pushing the app to Intune. You will need the Win32_application_add.ps1 you downloaded earlier. 

Add all apps to the script you created (please be aware of the detection rules, they are quite important). Also, please make sure the source file corresponds with the intunewinapp you have created. Here is an example for Java. 

Step3:  

You will notice the apps are not assigned (yet). So we need to set the availability to all users.  You will need the Application_Get_Assign.ps1 script you downloaded at the beginning. 

Again the Java example I used earlier 

#################################################### 

####java 

#################################################### 

$ApplicationName = “Chocolatey_Java” 

$Application = Get-IntuneApplication | ? { $_.displayName -eq “$ApplicationName” } 

$id = $application.id 

$uri = “https://graph.microsoft.com/beta/deviceAppManagement/mobileApps/$id/assignments” 

Invoke-RestMethod -Uri $uri –Headers $authToken –Method Get 

$contentpart1 = ‘{“intent”:”available”,”source”: “direct”,”sourceId”: null,”target”: {“@odata.type”: “#microsoft.graph.allLicensedUsersAssignmentTarget”}}’ 

$content = $contentpart1 

Invoke-RestMethod –Uri $uri –Headers $authtoken –Method Post -Body $content -ErrorAction Stop -ContentType ‘application/json’ 

Step 4: 

Okay? We have created the app, converted it to an intunewinapp, uploaded it and assigned it. Now it’s time to create the logo. That’s a little bit harder then you might think though. You will need fiddler to fetch some information. Take a look at my blog to start with fiddler: 

Close Encounters of Fiddler – Call4Cloud 

We need to have the plain text data we need for the “Largeicon” json part.  

win32LobApp resource type – Microsoft Graph v1.0 | Microsoft Docs 

The easiest way to get the information you need is manually uploading the logo you need and watch fiddler! 

Now that we have the information needed to create the logo we can begin to attach the logo to the app. You can use the same script to add the logo’s as you did to assign the apps. 

Again, I will use Java as the example: 

################################################### 

####java 

#################################################### 

$ApplicationName = "Chocolatey_java" 
$Application = Get-IntuneApplication | ? { $_.displayName -eq "$ApplicationName" } 

$id = $application.id 
$uri = "https://graph.microsoft.com/beta/deviceAppManagement/mobileApps/$id/" 

Invoke-RestMethod -Uri $uri –Headers $authToken –Method Get 

 $contentpart1 = '{"@odata.type":  "#microsoft.graph.win32LobApp","largeIcon":  { 

                      "type":  "image/jpeg", 

                      "value":  "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAsJCQcJCQcJCQkJCwkJCQkJCQsJCwsMCwsLDA0QDBEODQ4MEhkSJRodJR0ZHxwpKRYlNzU2GioyPi0pMBk7IRP/2wBDAQcICAsJCxULCxUsHRkdLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCz/wAARCADZAakDASIAAhEBAxEB/8QAGwABAQACAwEAAAAAAAAAAAAAAAECBgQFBwP/xABMEAACAgIBAQUDBwYJCAsAAAAAAQIDBBEFIQYSMUFRE2GBIiMycZGhsRQzQlKCsgcVFiQ0YnKiwSVUY3OS0dLxF0NEU1WDk5SV4vD/xAAaAQEBAQEBAQEAAAAAAAAAAAAAAQIDBAUG/8QAMREBAAICAAUDAgMHBQAAAAAAAAECAxEEEhMhMQVBUTJhBhRSIiOBobHB0TNiceHw/9oADAMBAAIRAxEAPwD1jqADysgAAAAAAAHUdQCh1HUABtlTZAFXbG2QAXbG2QFF2xtkAF2xtkBRdsbZB8Ci7Y2yfAAXbG2QAXbG2QAXbG2T4AC7Y2yAgu2NsgILtjbIALtjbICB1HUAIdR1AAdR1AAAAgAAAAAAAAhQAAAAAAAAAAAKAAAAAKAAoAAAACh6jTLrxKUYlAKABQJ0HQpAOLn3W4+Hm5FUVKdFM74xf6Xs13nH4raMsTJpzcbGy6Xuq+uFkH/a8vgTPlCODyMpfRjiZLl6aVcjXuw987OJtpk9rGyrIQ3+pOMbUvvZibatFXtpw/Pw1s36Zj+bagwDbxJpgo0QQAEAAEAAAAAQAAEAAQAAAAAAAACFAAAAAAAAAAAAAAUAAFAAUAAAABQLoaBoUEKNCFAKAAKGiPZT4X30Y1V199ka6qYOdk5PSiv9/oRYiZnUeXR9rc+OLxF9KaV2c/yauKfXu/Ssf2dPic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BNGmOmNMyA0aY6YMiE0aQFA0aQFA0aTTGmUBdP//Z" 
                  } 
}' 

$content = $contentpart1 

Invoke-RestMethod –Uri $uri –Headers $authtoken –Method patch -Body $content -ErrorAction Stop -ContentType ‘application/json’ 

 Open your Intune portal and take a look at the logo:

And you’re done! 

Conclusion: 

Imagine this scenario; you can just automatically push all your apps like this to all of your tenants. No more hard work to create all the apps manually. It will cost you some time to setup a baseline, but it’s wonderful it can all be done with PowerShell. 

Leave a Reply

Your email address will not be published. Required fields are marked *

26  +    =  27