0

So I have to automate a process that downloads an excel file from Microsofts Planner website. I have tried doing this 3 Different ways and have always hit a dead end. The only solution that seems to work is a script that imitates keypresses but is considered "bad practice" at my workplace.

First was obviously to use Microsoft Graph. It doesn't work because it would have to request for permissions from our companys MS ADMIN every time it makes an request. So thats a no go.

Edit: As @Crowcoder tried to anwser the post, his solution does not work. For it to work we would have to register into Azure Active Directory and we currently don't use it. (We use the MS local AD).

Then I have tried using GnuWin32 (Wget for windows). Doesn't work as it requires you to login 2 times and you can only put in creditentials once (Or maybe you can ? -> Couldn't figure out how).

After that I have tried to use the command for powershell. That comes close but also requires me to login with a popup.

Edit: Here we see the anwser from @lit which does not fit either. I have tried the solution and it promts a Google chrome alert login, and then also the MS Planner login (but you can put your creditentials only once as shown in the code below this).

Export-PlannerUserContent -UserAadIdOrPrincipalName -username -ExportDirectory "C:\pathToExport"

And for the end part the only solution that seems to work is the last one where I imitate keyboard presses to download the file. How the program runs:

  1. Open up chrome(With a shortcut to MS planner website)
  2. imitate keyboard presses to open DEV Console (ctrl+shift+J)
  3. Imitate keyboard so that imputs text(Javascript) to click the login into planner (if it exists, if not the function returns an error and skips this part)
  4. Imitate keyboard so that it inputs JS function that finds the necesary button and opens/presses the download button.
  5. after that it selects the 2nd pland and downloads it aswell (Same imitation of a keyboard textinput).

While this solution is the only one that "Works" I have been told that I should find a different solution as the keyboard simulator is not a viable solution for our company because of strict policies we have. Another reason why it cannot be used is because im trying to make this script run on our server with a service account that has no GUI. So I hit some sort of a dead end there as well.

EDIT: So What i'm trying to do here is implement a "headless" chrome that would do what it does now but can't seem to find a break trough.

So my question is does anybody have any tips, pointers or suggestions for improving the existing solutions or creating alternative ones that would be more appropriate.

Would love to hear your opinions on what I should research or do. I would also like to note that most API Calls don't work without heavy proxy configuration which I would like to avoid if possible.

Mastawayne
  • 19
  • 1
  • 4
  • 1
    You should be able to use Graph without the hassle you describe if you use Application Permissions instead of Delegated Permissions and the admin grants consent one time on the Azure App Registration. When I query planner tasks through graph explorer it uses Group.Read.All and Group.ReadWrite.All scopes. – Crowcoder May 12 '21 at 13:50
  • Useful doc https://learn.microsoft.com/en-us/office365/planner/export-user-data#:~:text=1%20Start%20Windows%20PowerShell.%20...%202%20Type%20the,be%20prompted%20to%20authenticate.%20...%20More%20items...%20 – lit May 12 '21 at 15:23
  • @Crowcoder Hello. Thank you for your anwser. Would you care to explain it into a bit more detail as I have tried to find the "Group" permissions and could not find them. I can only consent for basic "User" type permissions like User.ReadBasic.All & User.Read. Others require me to still get the authorization from my GA. – Mastawayne May 13 '21 at 06:37
  • @lit Thanks for the anwser but if you noticed I have mentioned "After that I have tried to use the command for powershell. That comes close but also requires me to login with a popup" in my post. Below that you see the script that I have gotten from the website you just mentioned, so unless you can give me any pointers on how to optimize it or "tinker" with it, I can already say it does not work in my envirovment. – Mastawayne May 13 '21 at 06:38
  • @lit I have also notice after reading the documentation again "You must be a global admin to run the PowerShell script for exporting your Planner user data." - I'm not GA hence the issue in the first place. – Mastawayne May 13 '21 at 06:48
  • @Crowcoder Hello, is there any way you could explain your solution in further detail? – Mastawayne May 18 '21 at 09:53
  • 1
    Apparently Graph [does not support Application permissions with Planner resources](https://learn.microsoft.com/en-us/graph/permissions-reference#remarks-7). So you would have to use Delegated, but that won't work if your users are not Active Directory users. – Crowcoder May 18 '21 at 10:37
  • @Crowcoder Okay lets say we add a user from AD to AAD, how would I create an service (I have been reading the docs but I still don't fully understand it). Do you create a service with some code that executes in the cloud aka. azure hosting of a virtual VM? Does the service "download" files to any location you want to or is it then specific to the azure online instance? The thing is even if it downloads the planner on an Azure VM, i'd have to somehow get it to our local server (which is heavly protected and restricted )and the DB and the Website that uses the exported planner is there. – Mastawayne May 18 '21 at 10:46
  • 1
    With delegated access you have to sign a user in and then get a token so you can call the API [on behalf of that user](https://learn.microsoft.com/en-us/graph/auth-v2-user). If your app signs the user in, then the next step is to have a [back end API pass along the authorization](https://learn.microsoft.com/en-us/azure/active-directory/develop/scenario-web-app-call-api-overview) to Graph. I don't have anything I can dump into an answer, it is not trivial but the docs aren't bad. – Crowcoder May 18 '21 at 10:57

0 Answers0