Scripts/MgGraph-Stuff.ps1
# Groupmembers $GroupName = "device_TestBIOSupdate" $MgGroup = Get-MgGroup -Filter "displayname eq '$($GroupName)'" $MgGroupMembers = Get-MgGroupMember -GroupId $MgGroup.Id $MgGroupMembers Get-MgGroupMember -GroupId 68e01767-ccfd-41fb-9154-8cfbe69a8ff6 | ForEach-Object { $_.AdditionalProperties | Format-Table } $MgGroupMembers | ForEach-Object { $_.AdditionalProperties | Format-Table } $Members = @( "C3692" "C3671" "C3707" "C3725" "C3704" "C3706" "C3570" "C3664" "C1799" "C3711" "C3722" "C3705" "C3513" "C3709" ) $GroupName = "devices_01" New-MgGroupMemberCustom -GroupName $GroupName -Members $Members # Groep aanmaken $GroupName = "devices_01" New-MgGroup -DisplayName $GroupName -MailEnabled:$False -MailNickname $GroupName -SecurityEnabled $CustomerCode = "ABC" $GroupName = "C_$($CustomerCode)_MDM_Devices_Windows10" $MembershipRule = "(device.deviceOSVersion -startsWith `"10.0.19`") and (device.managementType -eq `"MDM`") and (device.deviceOSType -eq `"Windows`")" $GroupName = "C_$($CustomerCode)_MDM_Devices_Windows11" $MembershipRule = "(device.deviceOSVersion -startsWith `"10.0.22`") and (device.managementType -eq `"MDM`") and (device.deviceOSType -eq `"Windows`")" $Params = @{ MembershipRule = $MembershipRule DisplayName = $GroupName MailEnabled = $false MailNickname = $GroupName SecurityEnabled = $true GroupTypes = "DynamicMembership" MembershipRuleProcessingState = "On" } New-MgGroup @Params # User aanmaken $Random = $(Get-Random -Minimum 1 -Maximum 10000) $UserPrincipalName = "test.$($Random)@youandme.com" $DisplayName = "Test $($Random)" $Password = "$(Get-Random)1n3uow8efs@@!#" Get-MgSubscribedSku | Format-List New-JAADUser -UserPrincipalName $UserPrincipalName -DisplayName $DisplayName -Password $Password Set-MgUserLicense -UserId $UserPrincipalName -AddLicenses @{SkuId = "710779e8-3d4a-4c88-adb9-386c958d1fdf" } -RemoveLicenses @() Update-MgUser -UserId $UserPrincipalName -Surname "Test" -GivenName "User" # Apps $Apps = Get-MgDeviceAppManagementMobileApp $Apps | Where-Object { $_.AdditionalProperties."@odata.type" -ne "#microsoft.graph.managedIOSStoreApp" -and $_.AdditionalProperties."@odata.type" -ne "#microsoft.graph.managedAndroidStoreApp" } $Apps | Where-Object { $_.AdditionalProperties."@odata.type" -eq "#microsoft.graph.win32LobApp" } $iosApps = $Apps | Where-Object { $_.AdditionalProperties."@odata.type" -eq "#microsoft.graph.iosVppApp" } $iosApps | Where-Object { $_.AdditionalProperties."@odata.type" -eq "#microsoft.graph.iosVppApp" } | Select-Object DisplayName, Publisher | Export-Excel # Voeg nieuwe Autopilot device toe aan een groep $ApDevices = Get-MgDeviceManagementWindowAutopilotDeviceIdentity -All | Where-Object DeploymentProfileAssignedDateTime -GT (Get-Date).AddDays(-7) | Select-Object AzureAdDeviceId $AzDevices = Get-MgDevice -All $ApDevices | ForEach-Object { $Device = $AzDevices | Where-Object DeviceId -EQ $_.AzureAdDeviceId $Device New-MgGroupMember -GroupId "68e01767-ccfd-41fb-9154-8cfbe69a8ff6" -DirectoryObjectId $Device.Id } # Teams WERKT NIET Get-MgTeam Get-MgTeamChannel -TeamId xxx $Params = @{ Body = @{ ContentType = "html" Content = "<h3>Hello World</h3>" } } New-MgTeamChannelMessage -TeamId "18d13f92-3f90-4f40-9411-fb6427f3ddee" -ChannelId "19:b585106cccd744b98b2a1cf96229afc5@thread.skype" -BodyParameter $Params # PS Intune Scripts # $Scripts = Get-MgDeviceManagementScript -All $Scripts = Invoke-GraphRequest -Uri "https://graph.microsoft.com/beta/deviceManagement/deviceManagementScripts/" $ScriptContent = $Scripts.value | ForEach-Object -ThrottleLimit 10 -Parallel { Invoke-GraphRequest -Uri "https://graph.microsoft.com/beta/deviceManagement/deviceManagementScripts/$($_.Id)" } $Output = @() $ScriptContent | ForEach-Object { $obj = [PSCustomObject]@{ displayName = $_.displayName fileName = $_.fileName scriptContent = [System.Text.Encoding]::ASCII.GetString([System.Convert]::FromBase64String($($_.scriptContent))) } $Output += $obj # } $Output | Sort-Object displayName | Format-Table $FolderPath = "$($env:TEMP)\$((Get-MgOrganization).DisplayName)-PsScripts" mkdir $FolderPath -Force code $FolderPath $Output | ForEach-Object { $_.scriptContent | Out-File -Encoding ASCII -FilePath $(Join-Path $FolderPath $($_.fileName)) } # Azure Groups Owners and Members $Groups = Get-MgGroup -All #| Where-Object GroupTypes -EQ 'Unified' $Result = @() foreach ($g in $Groups) { $g.Id $g.DisplayName $Team = Get-MgTeam -TeamId $g.Id -ea 0 Get-MgGroupMember -GroupId $g.Id | ForEach-Object { $obj = [PSCustomObject]@{ GroupId = $g.Id DisplayName = $g.DisplayName GroupMail = $g.Mail TeamsSite = $null UserType = "Member" UserName = $_.AdditionalProperties.displayName UserMail = $_.AdditionalProperties.mail UserPrincipalName = $_.AdditionalProperties.userPrincipalName UserJobTitle = $_.AdditionalProperties.jobTitle } if ($Team) { $obj.TeamsSite = "Yes" } $Result += $obj } Get-MgGroupOwner -GroupId $g.Id | ForEach-Object { $obj = [PSCustomObject]@{ GroupId = $g.Id DisplayName = $g.DisplayName GroupMail = $g.Mail TeamsSite = $null UserType = "Owner" UserName = $_.AdditionalProperties.displayName UserMail = $_.AdditionalProperties.mail UserPrincipalName = $_.AdditionalProperties.userPrincipalName UserJobTitle = $_.AdditionalProperties.jobTitle } if ($Team) { $obj.TeamsSite = "Yes" } $Result += $obj } } $Result | Export-Excel # User inventarisatie $Users = Get-MgUser -All $NewUsers = $Users | Where-Object UserType -EQ Member | ForEach-Object { $License = Get-MgUserLicenseDetail -UserId $_.id [PSCustomObject]@{ UserPrincipalName = $_.UserPrincipalName DisplayName = $_.DisplayName License = $License.SkuPartNumber } } $NewUsers | Format-Table -AutoSize |