-
Notifications
You must be signed in to change notification settings - Fork 327
Expand file tree
/
Copy pathForceSyncOnAllWindowsDevices-MgModule.ps1
More file actions
46 lines (36 loc) · 1.43 KB
/
ForceSyncOnAllWindowsDevices-MgModule.ps1
File metadata and controls
46 lines (36 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Install the module. (You need admin on the machine.)
# Install-Module Microsoft.Graph
Import-Module Microsoft.Graph.Authentication
Import-Module Microsoft.Graph.DeviceManagement
$TenantID = ""
$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')"
# Show Device Count
($Devices | Measure-Object).Count
# Report Last Sync, and force sync on each Device
Foreach ($Device in $Devices) {
Write-Host "Last Sync Time was: $($Device.lastSyncDateTime)"
# Force sync
Sync-MgDeviceManagementManagedDevice -ManagedDeviceId $Device.Id
Write-Host "Sending Sync request to Device with DeviceID $($Device.Id)" -ForegroundColor Yellow
Write-Host ""
}
#
# Misc samples
#
# Get all devices
Get-MgDeviceManagementManagedDevice -All
# Get devices for a specific user
$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-Object deviceName
# Get Single Device
$Devices = Get-MgDeviceManagementManagedDevice -Filter "deviceName eq 'PC001'"