How to Retrieve Dependency Apps in Win32 Scripts?

0
2
Asked By TechGuru99 On

Hi everyone! I'm trying to figure out how to get the dependencies of Win32 apps using a script. I've set up a basic script that loads necessary modules and connects to Microsoft Graph, but when I run it, I receive a dependency count without specific details on which apps are dependent. Here's the relevant part of my script:

```powershell
# Load Modules
$Modules = @("Microsoft.Graph.Authentication", "Microsoft.Graph.DeviceManagement")
foreach ($mod in $Modules) {
if (-not (Get-Module -ListAvailable -Name $mod)) {
Write-Error "Module required not installed: $mod"
return
}
try {
Import-Module $mod -ErrorAction Stop
Write-Host "Module loaded: $mod"
} catch {
Write-Error "Failed to load $mod: $_"
return
}
}

# Connect to Microsoft Graph
try {
Connect-MgGraph -Scopes "DeviceManagementApps.Read.All", "DeviceManagementApps.ReadWrite.All"
$ctx = Get-MgContext
if (-not $ctx -or -not $ctx.Account) {
throw "Connect-MgGraph has not established a valid session."
}
Write-Host "Connected as $($ctx.Account)"
} catch {
Write-Error "Graph connection failed: $_"
return
}

# App ID to test
$AppId = "e17a7748-a973-4adb-babf-c637462b7f1a"

# Build URL with $expand=dependencies
$uri = "https://graph.microsoft.com/beta/deviceAppManagement/mobileApps/$AppId?$expand=dependencies"

# Call Graph and handle response
try {
$responseRaw = Invoke-MgGraphRequest -Method GET -Uri $uri -OutputType Json
$response = $responseRaw | ConvertFrom-Json
if ($response.dependencies) {
Write-Host "Dependencies found: $($response.dependencies.Count)"
$response.dependencies | Format-Table dependencyAppId, dependencyType
} elseif ($response.dependentAppCount -gt 0) {
Write-Warning "The app has $($response.dependentAppCount) dependencies, but Graph returns nothing in .dependencies"
} else {
Write-Host "No declared dependencies."
}
} catch {
Write-Warning "Error during Graph call: $($_.Exception.Message)"
}
```

I see that $response.dependencies is not showing what I'd like, especially given that the result indicates there are dependent apps. So, does anyone have a better approach to retrieve these dependencies?

Also, is there a way to find out if one app is a dependency for another? Thanks a lot!

2 Answers

Answered By PowerShellFan32 On

Just a quick note on formatting—you're using inline code, which is harder to read. Try pasting your code in a block format for clarity. In many editors, you just need to highlight your code and hit tab to indent it properly before copying it here.

Answered By CodeMaster87 On

It looks like you're expecting dependencies in `$response.dependencies`, but you might want to check what that actually contains before trying to output. You could also move that formatting piece to the end of your output process. As for retrieving dependencies, I found that using the following URL gives you all relationships, including dependencies:

`https://graph.microsoft.com/beta/deviceAppManagement/mobileApps/$AppId/relationships/`

DevExpert23 -

So with that URL, you're seeing all the dependencies clearly?

ScriptNinja42 -

How did you discover that URL? It sounds useful!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.