Skip to content

Commit

Permalink
Updating scripts for Microsoft.Graph module v2
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewJNet committed Nov 17, 2023
1 parent b7a646d commit 641c864
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 10 deletions.
6 changes: 5 additions & 1 deletion Scripts/AzureAD/Get-AzureADAuditLogs-MgModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
Import-Module Microsoft.Graph.Authentication
Import-Module Microsoft.Graph.Reports
$TenantID = ""
$Scopes = @(
"AuditLog.Read.All",
"Directory.Read.All"
)

$Tenant = Connect-MgGraph -TenantId $TenantID -Scopes "AuditLog.Read.All","Directory.Read.All"
$Tenant = Connect-MgGraph -TenantId $TenantID -Scopes $Scopes

#Get all device logs
Get-MgAuditLogDirectoryAudit -Filter "category eq 'Device'"
Expand Down
23 changes: 14 additions & 9 deletions Scripts/Intune/ForceSyncOnAllWindowsDevices-MgModule.ps1
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
#Requires -Modules Microsoft.Graph
# Install the module. (You need admin on the machine.)
# Install-Module Microsoft.Graph
Import-Module Microsoft.Graph.Authentication
Import-Module Microsoft.Graph.DeviceManagement
$TenantID = ""

Select-MgProfile -Name "beta"
$Tenant = Connect-MgGraph -TenantId $TenantID -Scopes "DeviceManagementManagedDevices.Read.All","DeviceManagementManagedDevices.ReadWrite.All","DeviceManagementManagedDevices.PrivilegedOperations.All"
$Scopes = @(
"DeviceManagementManagedDevices.Read.All",
"DeviceManagementManagedDevices.ReadWrite.All",
"DeviceManagementManagedDevices.PrivilegedOperations.All"
)

$Tenant = Connect-MgGraph -TenantId $TenantID -Scopes $Scopes
# Get all Windows Devices
$Devices = Get-MgDeviceManagementManagedDevice -Filter "contains(operatingsystem, 'Windows')" | Get-MSGraphAllPages
$Devices = Get-MgDeviceManagementManagedDevice -Filter "contains(operatingsystem, 'Windows')"

# Show Device Count
($Devices | Measure-Object).Count

# Report Last Sync, and force sync on each Device
Foreach ($Device in $Devices)
{
Foreach ($Device in $Devices) {
Write-Host "Last Sync Time was: $($Device.lastSyncDateTime)"
# Force sync
Sync-MgDeviceManagementManagedDevice -ManagedDeviceId $Device.Id
Expand All @@ -30,12 +35,12 @@ Foreach ($Device in $Devices)
Get-MgDeviceManagementManagedDevice | Get-MSGraphAllPages

# Get devices for a specific user
$Devices = Get-MgDeviceManagementManagedDevice | Where-Object {$_.userDisplayName -eq "Bob Smith"}
$Devices | Select deviceName
$Devices = Get-MgDeviceManagementManagedDevice | Where-Object { $_.userDisplayName -eq "Bob Smith" }
$Devices | Select-Object deviceName

# Get Devices from wildcard
$Devices = Get-MgDeviceManagementManagedDevice -Filter "contains(deviceName, 'PC')"
$Devices | Select deviceName
$Devices | Select-Object deviceName

# Get Single Device
$Devices = Get-MgDeviceManagementManagedDevice -Filter "deviceName eq 'PC001'"
38 changes: 38 additions & 0 deletions Scripts/Intune/Update-Win32AppAssignmentsForDO-MgModule.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

# Install the module. (You need admin on the machine.)
# Install-Module Microsoft.Graph.Beta
# Uncomment line 38 to perform updates
Import-Module Microsoft.Graph.Authentication
Import-Module Microsoft.Graph.Beta.Devices.CorporateManagement
$TenantID = ""
$Scopes = @(
"DeviceManagementApps.ReadWrite.All"
)
$Tenant = Connect-MgGraph -TenantId $TenantID -Scopes $Scopes

$Apps = Get-MgBetaDeviceAppManagementMobileApp -Filter "contains(displayName, 'P2P')"
($Apps | Measure-Object).Count
$Apps | Select-Object displayName

foreach ($App in $Apps) {

$assignments = Get-MgBetaDeviceAppManagementMobileAppAssignment -MobileAppId $App.id
Write-Output "Working on: $($App.displayName)"
foreach ($assignment in $assignments) {
# Show info from assignment:
$assignment | ConvertTo-Json -Depth 5
$body = @{
"@odata.type" = "microsoft.graph.mobileAppAssignment"
target = @{
"@odata.type" = "microsoft.graph.allLicensedUsersAssignmentTarget"
}
# Create settings array for DO Foreground setting
settings = @{
"@odata.type" = "microsoft.graph.win32LobAppAssignmentSettings"
deliveryOptimizationPriority = "Foreground"
}
}
#Update-MgBetaDeviceAppMgtMobileAppAssignment -MobileAppId $App.id -mobileAppAssignmentId $assignment.Id -BodyParameter $body
}
}

0 comments on commit 641c864

Please sign in to comment.