powershell
7 TopicsGet-MgProfile : The term 'Get-MgProfile' is not recognized as the name of a cmdlet, function, script
Hi everyone, The cmdlet Get-MgProfile is no longer available after updating to v2.1.0 Even the link is no longer available: https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.people/get-mguserprofile What is the replacement Graph SDK cmdlet to get the existing Microsoft Graph PowerShell SDK connection profile name? Thanks in advance.16KViews1like5Commentsremove-mgplannertask official documentation wrong?
we have a very small project to remove old planner tasks. what we are having issue with when playing around with powershell graph sdk is the remove-mgplannertask command. firstly, the example in the official documentation seems to be wrong. Remove-MgPlannerTask -PlannerTaskId $plannerTaskId-If-Match W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBAWCc=" if we do it like this it comes up with a 'there is no positional parameter'. even the code snippet section of graph explorer has the same example. if we use the actual parameter as defined in the help e.g. Remove-MgPlannerTask -PlannerTaskId $plannerTaskId -IfMatch W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBAWCc=" this would come up as a invalid value. what kind of works is: Remove-MgPlannerTask -PlannerTaskId $plannerTaskId -IfMatch 'W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBAWCc="' however, with our actual task ID and related etag, it comes up with a etag is tool old. but when using graph explorer... using the sameetag value, it works fine. any help would be good. in the meantime, we wont use the powershell SDK and look at using the invoke-restmethod / invoke-webrequest to send a delete command.427Views0likes0CommentsPowershell Microsoft Graph SDK issues, insufficient permissions
I'm new to Microsoft Graph. I seem to be having basic authentication issues that I do not know how to work past. I'm trying to get information out of Azure AD and/or Intune to gather information regarding devices, specifically bitlocker recovery keys. Before getting that far, I'm just doing basic Get-mgdevice but I get insufficient privileges. I'm just using the Connect-MgGraph cmdlet with no parameters. Doing this I get connected but I guess my default permissions are too limited in this method. I am a Cloud Device Administrator though for testing purposes but at some point need to narrow down these permissions. At any rate if I try to connect with Connect-MgGraph -Scopes "Device.Read.All" I'm lead to a page that says admin consent is required. Apparently I'm not the correct sort of admin so I cannot consent. With that said I'm trying to right a script for many users to run so I don't want them to all have ability to consent anything. I just want the script to run. So I don't know what I'm doing and am at a roadblock. All the documentation I find makes little sense to me so apparently. Note: I have another script that uses Connect-MSGraph cmdlet (like many sample scripts I find) but I cannot find the difference between MSGraph and MgGraph. Also it is my understanding this information can be found both in AzureAD as well as Intune with Intune possibly having different cmdlets? So confusing. Any guidance is appreciated. TIA.Solved1.9KViews1like2CommentsUnable to Export All Channels Conversations from a Team using Graph-PowerShell
I'm using the below script to export channel conversations. It works fine per channel. But I want to be able to export all channel conversations in a Team. I tried using ForEach ($Channel in $Channels) but it's not working. Can someone help please. Credit to PSGuy for the original script: https://www.psguy.eu/how-to-export-ms-teams-chat-to-html-file-for-backup/ [CmdletBinding(DefaultParameterSetName='default')] param ( [Parameter(ParameterSetName='Channel')] $Team, [Parameter(Mandatory=$false,ParameterSetName='default')] [Parameter(Mandatory=$true,ParameterSetName='Channel')] $Channel ) Write-Host "Exporting Team Chats Homie" $scriptpath = $MyInvocation.MyCommand.Path $dir = Split-Path $scriptpath $Date = Get-Date -Format "MM-dd-yyyy-HHmm" $clientId = "YourClientID" $tenantName = "YourTenantName" $clientSecret = "YourClientSecret" $resource = "https://graph.microsoft.com/" $ReqTokenBody = @{ Grant_Type = "Password" client_Id = $clientID Client_Secret = $clientSecret Username = 'YourTeamsAdmUserName' Password = 'YourTeamsAdmPassword' Scope = "https://graph.microsoft.com/.default" } $TokenResponse = Invoke-RestMethod -Uri "https://login.microsoftonline.com/$TenantName/oauth2/v2.0/token" -Method POST -Body $ReqTokenBody #Getting all Groups $apiUrl = "https://graph.microsoft.com/beta/groups" $Data = Invoke-RestMethod -Headers @{Authorization = "Bearer $($TokenResponse.access_token)"} -Uri $apiUrl -Method Get -ErrorVariable RespErr $Groups = ($Data | Select-Object Value).Value if ($Team -eq $NULL){ Write-Host "You have" -NoNewline Write-Host " $($Groups.Count)" -ForegroundColor Yellow -NoNewline Write-Host " teams." Write-Host "" Write-Host "Messages from which Team do you want to export to the HTML format?" -ForegroundColor Yellow $Groups | FT DisplayName,Description $Team = Read-Host "Type one of the Team (DisplayName)" } $TeamID = ($Groups | Where-Object {$_.displayname -eq "$($Team)"}).id $apiUrl = "https://graph.microsoft.com/v1.0/teams/$TeamID/Channels" $Data = Invoke-RestMethod -Headers @{Authorization = "Bearer $($TokenResponse.access_token)"} -Uri $apiUrl -Method Get if ($Channel -eq $NULL){ Write-Host "You choose" -NoNewline Write-Host " $($Team)" -ForegroundColor Yellow -NoNewline Write-Host " Team." Write-Host "" $Channels = ($Data | Select-Object Value).Value Write-Host "Messages from which Channel do you want to export to the HTML format?" -ForegroundColor Yellow $Channels | FT DisplayName,Description $Channel = Read-Host "Type one of the Channel(DisplayName)" } $ChannelID = (($Data | Select-Object Value).Value | Where-Object {$_.displayName -eq "$($Channel)"}).ID $apiUrl = "https://graph.microsoft.com/beta/groups/$TeamID/members" $Data = Invoke-RestMethod -Headers @{Authorization = "Bearer $($TokenResponse.access_token)"} -Uri $apiUrl -Method Get class messageData { [string]$dateTime [string]$from [string]$body messageData() { $this.dateTime = "" $this.from = "" $this.body = "" } } function parseMessage($Data) #returns resultset { $messages = ($Data | Select-Object Value).Value foreach ($message in $Messages) { $messageID = $message.id $messageSet = New-Object System.Collections.ArrayList; $result = New-object messageData #parse message if ($NULL -eq $message.from.user.displayName) { $result.dateTime = $message.createdDateTime $result.from = $message.from.application.displayName } else { $result.dateTime = $message.createdDateTime $result.from = $message.from.user.displayName } $bodyOut = "" if ($NULL -eq $message.summary) { foreach ($attachment in $message.attachments) { $output = $attachment.content $output = $output.substring(14) $output = $output.substring(0,$output.length-4) $bodyOut = $bodyOut + $output } } else { $bodyOut = $message.summary; } $bodyOut = $bodyOut + $message.body.content $result.body = $bodyOut; $messageSet.Add($result) #parse replies $repliesURI = "https://graph.microsoft.com/beta/teams/" + $TeamID + "/channels/" + $ChannelID + "/messages/" + $messageID + "/replies?`$top100" $repliesResponse = Invoke-RestMethod -Method Get -Uri $repliesURI -Headers @{Authorization = "Bearer $($TokenResponse.access_token)"} foreach ($reply in $repliesResponse.value ) { $replyData = New-Object messageData if ($NULL -eq $reply.from.user.displayName) { $replyData.dateTime = $reply.createdDateTime $replyData.from = $reply.from.application.displayName } else { $replyData.dateTime = $reply.createdDateTime $replyData.from = $reply.from.user.displayName } $bodyOut = "" if ($NULL -eq $message.summary) { foreach ($attachment in $reply.attachments) { $output = $attachment.content $output = $output.substring(14) $output = $output.substring(0,$output.length-4) $bodyOut = $bodyOut + $output } } else { $bodyOut = $message.summary } $replyData.body = $bodyOut + $reply.body.content $messageSet.Add($replyData) } $resultList.Add($messageSet) } return } $TokenResponse = Invoke-RestMethod -Uri "https://login.microsoftonline.com/$TenantName/oauth2/v2.0/token" -Method POST -Body $ReqTokenBody $resultList = New-Object System.Collections.ArrayList; $apiUrl = "https://graph.microsoft.com/beta/teams/$TeamID/channels/$ChannelID/messages?`$top=100" $sourceData = Invoke-RestMethod -Headers @{Authorization = "Bearer $($TokenResponse.access_token)"} -Uri $apiUrl -Method Get parseMessage($sourceData) $nextLink = $sourceData.'@Odata.NextLink' while ($NULL -ne $nextLink) { $nextURL = $nextLink; $sourceData = Invoke-RestMethod -Headers @{Authorization = "Bearer $($TokenResponse.access_token)"} -Uri $nextURL -Method Get parseMessage($sourceData) $nextLink = $sourceData.'@Odata.NextLink' } $resultFieldSet = New-Object System.Collections.ArrayList foreach($resultData in $resultList) { $resultFields = $resultData | Select-Object @{Name = 'DateTime'; Expression = {Get-Date -Date (($_).dateTime) -Format 'MM/dd/yyyy hh:mm:ss.fff tt'}}, @{Name = 'From'; Expression = {((($_).from))}}, @{Name = 'Message'; Expression = {(($_).body) -replace '<.*?>',''}}| Sort-Object DateTime $resultFieldSet.Add($resultFields) } $Header = @" <style> h1, h5, th { text-align: center; } table { margin: auto; font-family: Segoe UI; box-shadow: 10px 10px 5px #888; border: thin ridge grey; } th { background: #0046c3; color: #fff; max-width: 400px; padding: 5px 10px; } td { font-size: 11px; padding: 5px 20px; color: #000; } tr { background: #b8d1f3; } tr:nth-child(even) { background: #dae5f4; } tr:nth-child(odd) { background: #b8d1f3; } </style> "@ $count = 0 foreach ($resultCount in $resultList){ $count = $count + $resultCount.Count } $body = "<body><b>Generated:</b> $(Get-Date -Format 'MM/dd/yyyy hh:mm tt') <br><br> <b>Team Name:</b> $($Team) <br> <b>Channel Name:</b> $($Channel) <br><br>" + "<b>number of messages:</b> " + $count + " <br><br>" $body = $body + "</head>" $resultHtml = "" foreach ($resultFields in $resultFieldSet){ $tempHtml = $resultFields | ConvertTo-Html -Head $header $resultHtml = $tempHtml + "<br>" + $resultHtml } $resultHtml = $body + "<br>" + $resultHtml $Export = "$dir\TeamsHistory\$Team-$Channel" New-Item -ItemType Directory -Path $Export -ErrorAction Ignore $resultHtml | Out-File $Export\$Team-$Channel-$Date.html Write-Host " " Write-Host "Messages from the" -NoNewline Write-Host " $($Team)" -NoNewline -ForegroundColor Yellow Write-Host " team and" -NoNewline Write-Host " $($Channel)" -NoNewline -ForegroundColor Yellow Write-Host " channel were generated and saved to the" -NoNewline Write-Host " $($Export)" -NoNewline -ForegroundColor Yellow Write-Host " as a" -NoNewline Write-Host " $($Team)-$($Channel)-$($Date).html" -NoNewline -ForegroundColor Yellow Write-Host " file." Write-Host " "1.3KViews0likes2CommentsUnable to create Azure AD user using Graph API
Note I'm somewhat new to using the Graph API, so please forgive me (and correct me) if my terminology is wrong 👍 As I understand, https://docs.microsoft.com/en-us/graph/api/user-post-users documents that it should be possible for an Application to call the API and specifies the required permissions, headers and body to create a new Azure AD user account. Using PowerShell, I've tried a POST to both the v1.0 and beta endpoints with an authorization token that has the appropriate permissions assigned to create a new user account, but in both cases I see the following error: Invoke-RestMethod : The remote server returned an error: (400) Bad Request. The parameters I passed are a variation of those from https://docs.microsoft.com/en-us/graph/api/user-post-users?view=graph-rest-1.0&tabs=http#example-1-create-a-user (with the user principal name amended to have the appropriate suffix for the tenant in question, and a different password). When I run the following try { Invoke-RestMethod -Headers $header -Uri $uri -Method "POST" -Body $userparams -ErrorAction Stop } catch [System.Net.WebException] { if ($_.Exception.Response -eq $null) { throw } $streamReader = [System.IO.StreamReader]::new($_.Exception.Response.GetResponseStream()) $streamReader.BaseStream.Position = 0 $streamReader.ReadToEnd() | ConvertFrom-Json } I see the "(400) Bad Request" error is apparently due to an invalid passwordProfile: @{code=Request_BadRequest; message=Invalid property 'PasswordProfile'.; innerError=} Amending the properties of the passwordProfile object according to https://docs.microsoft.com/en-us/graph/api/resources/passwordprofile?view=graph-rest-1.0 hasn't helped. If I entirely remove the passwordProfile parameter from the body of my POST I get a slight variation on the exception.response inasmuch as it says: @{code=Request_BadRequest; message=A password must be specified to create a new user.; innerError=} Having checked, I am also unable to create a new user account when using a Delegated (work or school account) to call the same API and specify the same headers and body, with the same resulting errors. Note, I am able to create a new user account using https://docs.microsoft.com/en-us/powershell/module/microsoft.graph.users/new-mguser?view=graph-powershell-beta (version https://www.powershellgallery.com/packages/Microsoft.Graph.Users/1.9.2) using exactly the same body parameters, so I have hope that the parameters are defined correctly after all Can anyone help me understand what I need to do to be able to create users using the Graph API, ideally with Application permissions?Solved5.9KViews0likes1CommentWith Graph API we are only getting 1000 devices
HI Team, We are using the below PowerShell script to change the Primary user of a device by checking the last logged in userid. Below is the github repo link which holds this PowerShell script and also the link of an article about the explanation of this script - https://raw.githubusercontent.com/svdbusse/IntuneScripts/master/PrimaryUser/Set-PrimaryUserfromLastLogIn.ps1 https://svdbusse.github.io/SemiAnnualChat/2020/03/21/Changing-Intune-Primary-User-To-Last-Logged-On-User.html The problem now is that we are only able to get 1000 devices in the $Devices variable in the above mentioned script and we have around 2000 devices so 1000 more devices are not getting fetched by this script. Also this script always get the device in the same pattern i.e.. if I run the script today and tomorrow then the devices will show the same pattern that is also the reason the rest 1000 devices are not getting fetched. Any solution to this issue will be a great help for me. Regards, Ashish Arya584Views0likes0CommentsApplication.ReadWrite.OwnedBy: List all applications owned by the calling application
Hi, I am trying to get only the applications that my app owns using Graph, and on the documentation it shows that I should be able to only list the applications where my app is owner. (This is to limit the content I have access to with my app) https://docs.microsoft.com/en-us/graph/permissions-reference Application Application.Read.All: List all applications (GET /beta/applications) Application.ReadWrite.All: Delete a service principal (DELETE /beta/servicePrincipals/{id}) Application.ReadWrite.OwnedBy: Create an application (POST /beta/applications) Application.ReadWrite.OwnedBy: List all applications owned by the calling application (GET /beta/servicePrincipals/{id}/ownedObjects) Application.ReadWrite.OwnedBy: Add another owner to an owned application (POST /applications/{id}/owners/$ref). NOTE: This may require additional permissions. However, if I create an app that has owner permissions on another app and I query against the Graph API "Applications" I am still able to list all applications in the tenant. I thought having me added as owner, on an application and having only that permission on my app, would limit my result ? Am I missing something here? Adding the app as an owner in the following way: Connect-AzureAD $objectIdOfApplicationToChange = Get-AzureADApplication -objectId "6929067b-b9ab-4bf6-bb17-81be5eb31ba1" $objectIdOfApplicationThatNeedsToBeAdded = Get-AzureADApplication -ObjectId "21780578-3035-47c1-8096-a1641ab3123d" Add-AzureAdApplicationOwner -ObjectId $objectIdOfApplicationToChange.ObjectId -RefObjectId (get-azureadserviceprincipal -all $true | where-object {$_.AppId -like $objectIdOfApplicationThatNeedsToBeAdded.AppId}).ObjectId When I query the Graph through PowerShell, I was hoping to get a 403 when querying all applications... Anyone tried to limit the result you get back using this permission ? It is not a wanted solution to give permissions to read all applications for this app, therefor we need to limit the access...8.8KViews0likes1Comment