Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
46b596e
Adding allusers and alldevices logic
markstan Dec 10, 2018
1ff9832
Merge pull request #1 from markstan/markstan-patch-1
markstan Dec 10, 2018
d317e1b
Update Validate-NDESConfiguration.ps1
markstan Jan 17, 2019
51f1511
Merge pull request #2 from markstan/markstan-patch-2
markstan Jan 17, 2019
659b0e2
Update Win10_PrimaryUser_Get.ps1
markstan Oct 30, 2020
1c34456
Merge branch 'master' of https://github.com/microsoftgraph/powershell…
markstan Oct 30, 2020
50f2e7d
Merge branch 'master' of https://github.com/markstan/powershell-intun…
markstan Oct 30, 2020
56a3c6a
Endpoint Security Samples addition
davefalkus Nov 21, 2020
d0f46cf
App Only Authentication Sample Addition
davefalkus Dec 29, 2020
6c92506
Fix for issue 125
davefalkus Dec 29, 2020
278a5e6
Fix for issue #116
davefalkus Dec 29, 2020
0d99f19
Fix for issue #109
davefalkus Dec 29, 2020
673713d
Update Validate-NDESUrl.ps1 (#145)
WplusAzureAuto Dec 29, 2020
6584822
Update UsageSummary API Endpoint (#120)
dcluomax Dec 29, 2020
ddc6aef
Sample update for issue #154
davefalkus Dec 30, 2020
5a78ad3
Added noDependencies flag to YAML header
jasonjoh Apr 14, 2021
c713a42
Filter samples addition
davefalkus May 11, 2021
a9d99f3
Merge branch 'master' of https://github.com/microsoftgraph/powershell…
davefalkus May 11, 2021
616339a
Change MDATP App naming to defender for Endpoint (#170)
CorneDeJong Aug 1, 2021
59fc607
HB of localized readme files (#127)
OfficeGlobal Aug 1, 2021
8f22163
Application_MDM_Export.ps1 invalid characters (#186)
ChadSimmons Oct 12, 2021
72ea745
Add Application_Detected_Apps_Get.ps1
markstan Jan 13, 2022
efcb30a
Merge branch 'master' of https://github.com/markstan/powershell-intun…
markstan Jan 13, 2022
c06978d
Fixup for new version of cert connector
markstan Oct 3, 2022
e550d52
Changing default to unattended mode
markstan Oct 5, 2022
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
287 changes: 287 additions & 0 deletions Applications/Application_Detected_Apps_Get.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,287 @@

<#

.COPYRIGHT
Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
See LICENSE in the project root for license information.

#>

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

function Get-AuthToken {

<#
.SYNOPSIS
This function is used to authenticate with the Graph API REST interface
.DESCRIPTION
The function authenticate with the Graph API Interface with the tenant name
.EXAMPLE
Get-AuthToken
Authenticates you with the Graph API interface
.NOTES
NAME: Get-AuthToken
#>

[cmdletbinding()]

param
(
[Parameter(Mandatory=$true)]
$User
)

$userUpn = New-Object "System.Net.Mail.MailAddress" -ArgumentList $User

$tenant = $userUpn.Host

Write-Host "Checking for AzureAD module..."

$AadModule = Get-Module -Name "AzureAD" -ListAvailable

if ($AadModule -eq $null) {

Write-Host "AzureAD PowerShell module not found, looking for AzureADPreview"
$AadModule = Get-Module -Name "AzureADPreview" -ListAvailable

}

if ($AadModule -eq $null) {
write-host
write-host "AzureAD Powershell module not installed..." -f Red
write-host "Install by running 'Install-Module AzureAD' or 'Install-Module AzureADPreview' from an elevated PowerShell prompt" -f Yellow
write-host "Script can't continue..." -f Red
write-host
exit
}

# Getting path to ActiveDirectory Assemblies
# If the module count is greater than 1 find the latest version

if($AadModule.count -gt 1){

$Latest_Version = ($AadModule | select version | Sort-Object)[-1]

$aadModule = $AadModule | ? { $_.version -eq $Latest_Version.version }

# Checking if there are multiple versions of the same module found

if($AadModule.count -gt 1){

$aadModule = $AadModule | select -Unique

}

$adal = Join-Path $AadModule.ModuleBase "Microsoft.IdentityModel.Clients.ActiveDirectory.dll"
$adalforms = Join-Path $AadModule.ModuleBase "Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll"

}

else {

$adal = Join-Path $AadModule.ModuleBase "Microsoft.IdentityModel.Clients.ActiveDirectory.dll"
$adalforms = Join-Path $AadModule.ModuleBase "Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll"

}

[System.Reflection.Assembly]::LoadFrom($adal) | Out-Null

[System.Reflection.Assembly]::LoadFrom($adalforms) | Out-Null

$clientId = "d1ddf0e4-d672-4dae-b554-9d5bdfd93547"

$redirectUri = "urn:ietf:wg:oauth:2.0:oob"

$resourceAppIdURI = "https://graph.microsoft.com"

$authority = "https://login.microsoftonline.com/$Tenant"

try {

$authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList $authority

# https://msdn.microsoft.com/en-us/library/azure/microsoft.identitymodel.clients.activedirectory.promptbehavior.aspx
# Change the prompt behaviour to force credentials each time: Auto, Always, Never, RefreshSession

$platformParameters = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.PlatformParameters" -ArgumentList "Auto"

$userId = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.UserIdentifier" -ArgumentList ($User, "OptionalDisplayableId")

$authResult = $authContext.AcquireTokenAsync($resourceAppIdURI,$clientId,$redirectUri,$platformParameters,$userId).Result

# If the accesstoken is valid then create the authentication header

if($authResult.AccessToken){

# Creating header for Authorization token

$authHeader = @{
'Content-Type'='application/json'
'Authorization'="Bearer " + $authResult.AccessToken
'ExpiresOn'=$authResult.ExpiresOn
}

return $authHeader

}

else {

Write-Host
Write-Host "Authorization Access Token is null, please re-run authentication..." -ForegroundColor Red
Write-Host
break

}

}

catch {

write-host $_.Exception.Message -f Red
write-host $_.Exception.ItemName -f Red
write-host
break

}

}

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

Function Get-DetectedApps(){

<#
.SYNOPSIS
This function is used to get Managed Devices from the Graph API REST interface
.DESCRIPTION
The function connects to the Graph API Interface and gets Managed Devices
.EXAMPLE
Get-ManagedDevices
Returns Managed Devices configured in Intune
.NOTES
NAME: Get-ManagedDevices
#>

[cmdletbinding()]

$graphApiVersion = "Beta"
$Resource = "deviceManagement/detectedApps"

try {

$uri = "https://graph.microsoft.com/$graphApiVersion/$($Resource)"

$DetectedAppsResponse = (Invoke-RestMethod -Uri $uri -Headers $authToken -Method Get)


$DetectedApps = $DetectedAppsResponse.value

$DetectedAppsNextLink = $DetectedAppsResponse."@odata.nextLink"

while ($DetectedAppsNextLink -ne $null){

$DetectedAppsResponse = (Invoke-RestMethod -Uri $DetectedAppsNextLink -Headers $authToken -Method Get)
$DetectedAppsNextLink = $DetectedAppsResponse."@odata.nextLink"
$DetectedApps += $DetectedAppsResponse.value

}

return $DetectedApps

}

catch {

$ex = $_.Exception
$errorResponse = $ex.Response.GetResponseStream()
$reader = New-Object System.IO.StreamReader($errorResponse)
$reader.BaseStream.Position = 0
$reader.DiscardBufferedData()
$responseBody = $reader.ReadToEnd();
Write-Host "Response content:`n$responseBody" -f Red
Write-Error "Request to $Uri failed with HTTP Status $($ex.Response.StatusCode) $($ex.Response.StatusDescription)"
write-host
break

}

}

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

#region Authentication

write-host

# Checking if authToken exists before running authentication
if($global:authToken){

# Setting DateTime to Universal time to work in all timezones
$DateTime = (Get-Date).ToUniversalTime()

# If the authToken exists checking when it expires
$TokenExpires = ($authToken.ExpiresOn.datetime - $DateTime).Minutes

if($TokenExpires -le 0){

write-host "Authentication Token expired" $TokenExpires "minutes ago" -ForegroundColor Yellow
write-host

# Defining User Principal Name if not present

if($User -eq $null -or $User -eq ""){

$User = Read-Host -Prompt "Please specify your user principal name for Azure Authentication"
Write-Host

}

$global:authToken = Get-AuthToken -User $User

}
}

# Authentication doesn't exist, calling Get-AuthToken function

else {

if($User -eq $null -or $User -eq ""){

$User = Read-Host -Prompt "Please specify your user principal name for Azure Authentication"
Write-Host

}

# Getting the authorization token
$global:authToken = Get-AuthToken -User $User

}

#endregion

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

$DetectedApps = Get-DetectedApps

if($DetectedApps){

foreach($detectedApp in $DetectedApps){

write-host "Detected app" $detectedApp.displayName "found..." -ForegroundColor Yellow
Write-Host
$detectedApp

}

}

else {

Write-Host
Write-Host "No detected apps found..." -ForegroundColor Red
Write-Host

}


4 changes: 2 additions & 2 deletions Applications/Application_MDM_Export.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ $Resource = "deviceAppManagement/mobileApps"
else {

$uri = "https://graph.microsoft.com/$graphApiVersion/$($Resource)"
(Invoke-RestMethod -Uri $uri Headers $authToken Method Get).Value | ? { (!($_.'@odata.type').Contains("managed")) -and (!($_.'@odata.type').Contains("#microsoft.graph.iosVppApp")) -and (!($_.'@odata.type').Contains("#microsoft.graph.windowsAppX")) -and (!($_.'@odata.type').Contains("#microsoft.graph.androidForWorkApp")) -and (!($_.'@odata.type').Contains("#microsoft.graph.windowsMobileMSI")) -and (!($_.'@odata.type').Contains("#microsoft.graph.androidLobApp")) -and (!($_.'@odata.type').Contains("#microsoft.graph.iosLobApp")) -and (!($_.'@odata.type').Contains("#microsoft.graph.microsoftStoreForBusinessApp")) }
(Invoke-RestMethod -Uri $uri -Headers $authToken -Method Get).Value | ? { (!($_.'@odata.type').Contains("managed")) -and (!($_.'@odata.type').Contains("#microsoft.graph.iosVppApp")) -and (!($_.'@odata.type').Contains("#microsoft.graph.windowsAppX")) -and (!($_.'@odata.type').Contains("#microsoft.graph.androidForWorkApp")) -and (!($_.'@odata.type').Contains("#microsoft.graph.windowsMobileMSI")) -and (!($_.'@odata.type').Contains("#microsoft.graph.androidLobApp")) -and (!($_.'@odata.type').Contains("#microsoft.graph.iosLobApp")) -and (!($_.'@odata.type').Contains("#microsoft.graph.microsoftStoreForBusinessApp")) }

}

Expand Down Expand Up @@ -422,4 +422,4 @@ else {
Write-Host "No MDM Applications added to the Intune Service..." -ForegroundColor Red
Write-Host

}
}
Loading