How to quickly get the Group ID for an Office 365 Group

Microsoft Graph typically requires us to use the Group ID when working with O365 groups and modern sites. But Group ID can be tricky to find since it is rarely displayed. Here are some ways I found to quickly get hold of it during when experimenting with MS Graph:

1. The group ID is made available on our trusty old friend _spPageContextInfo  in the group’s SharePoint site. Knowing this we can easily find it by going to the site and type _spPageContextInfo.groupId  in the JS console. _spPageContextInfo is however not available on modern pages, but you can go to a page that is not modern such as Site Settings to find it.

2. Using Graph Explorer we can query for the group. By default mailNickname is used for the site URL. So if the site URL is  then GET$filter=mailNickname eq 'MyTeamSite'&$select=id  will give you the Group ID. Note that mailNickname is  not guaranteed to be the same as the site URL, for example if you have changed the site URL.

3. Group ID is also hidden deep in the page source of modern sites. To find it you can view the page source (CTRL+U) and search for spPageContextInfo. Triple click the paragraph you found to select it, copy the paragraph to the clipboard, open the JS console and paste it between two brackets { CTRL+V } and press enter. Now you can easily inspect the object and find the group id.

4. We can actually get to the page context object on modern pages too, but it is hidden deep down: window.spModuleLoader._bundledComponents["b6917cb1-93a0-4b97-a84d-7cf49975d4ec"].PageManager._instance.pageContext.legacyPageContext.groupId (FYI: The GUID here refers to the web scoped feature for “modern” pages.). I made a bookmarklet to make it easier to access:  javascript:void%20function(){alert(window.spModuleLoader._bundledComponents[%22b6917cb1-93a0-4b97-a84d-7cf49975d4ec%22].PageManager._instance.pageContext.legacyPageContext.groupId)}();

Posted in Tips | Tagged , , , , | 2 Comments

Excluding external users from search results in SharePoint Online

Search in SharePoint Online returns both internal and external users by default. This may  not be desirable. Here’s how to exclude external users from the search results.

External users have account names containing #ext# which makes them easy to filter out. Typically when you search for people you will query against the Local People Results result source. In SharePoint Online we can’t modify this result source like On Premises, but we can clone it and add our own custom filters:

  1. Open SharePoint Admin
  2. Go to search settings and select Manage Result Sources
  3. Copy Local People Results (click the down arrow to find the copy command)
  4. Edit your new result source and find Query Transform
  5. Add  -AccountName:"#ext#"  to the query
  6. Verify that it works using the Query Builder
  7. Save

Remember that you will need to configure search pages and other solutions to use this new result source instead of the default Local People Results!

Posted in Tips | Tagged , | 2 Comments

Try this if sound in Windows stops working

Several of my computers have had problems with sound suddenly not working. Typically this seems to happens when switching context, such as going from plugged in to battery, but sometimes it seems random. At work we use Skype for Business. When it encounters sound problems it tends to freeze up. I’ve found the following to work at restoring sound (and S4B) again:

  1. Right click on the sound icon in system tray. Select “Playback Devices”.
  2. Double click on “Speakers / Headphones”. Go to the “Advanced” tab in the dialog that opens:
  3. Click on “Restore Defaults” or the “Test” button:

Depending on the problem you have, one of these buttons tends to restore sound playback again!

Posted in Tips | Tagged , , , , , , | Leave a comment

Enable Mometum on an Alps Glidepoint Touchpad

My old computer has a touchpad from Synaptics with a feature called “Momentum”. (I’ve also seen this called “Inertia” och “Inertial Scrolling”.) It causes the mouse pointer move a little bit before stopping after you’ve released your finger, as if friction is slowing it down. I find this makes using a touchpad more enjoyable, since it allows you to flick your finger when moving the mouse.

My new computer came with  an Alps Glidepoint Touchpad. I was disappointed when I could not find any momentum settings in the settings. So I started digging through the registry to see if I could find some hidden settings, and I did!

Simply find this key using RegEdit and set it to 1 :

You can easily test the new setting by toggling the touch pad on/off in the settings dialog:

Sadly I find that the Alps implementation of momentum applies too much “friction”, making the mouse stop too fast. I have not been able to find any settings controlling this. If you do, please post a comment!

Posted in Tips | Tagged , , , , | 1 Comment

Stopping Software Center from restarting your computer

IT-departments may require you to restart your computer to complete updates they have pushed out. This is at best annoying, at worst it can ruin your work if you for example have a long running process in progress. (My personal favorite is when the company forced me to restart my computer in the middle of a service window when I was upgrading a system for said company…)

Note: Skip to Update 2 at the bottom for the latest working method!

If your company uses System Center you may recognize the following dialog informing you that Your Computer is About to Restart:

You can’t close this window or ask it to stop the shut down. So what can you do? I’ve seen others talk about shutting down Windows Services. That never worked for me, but I discovered that there was an easy way to stop the process. Simply open a command prompt and type  shutdown /a

This will abort the shutdown:

The countdown window will still be open, but when reaching zero nothing will happen!

Now you can finish your work at your own pace, before restarting your computer.

Note: If it does not work and you get a message that there is no shutdown in progress, try again later. I’m guessing that the shutdown command is not issued until 15-30 minutes before it should go off. Let me know in the comments if it works.

Update: Since the update window is “always on top” and can’t be closed it blocks your view in a pretty annoying way. Luckily we can use a bit of PowerShell and WinAPI to to hack the window properties to hide it :-)


Update 2: Above does not work for me anymore. But I found that you can simply stop the service:

  1. Open Services (run -> services.msc)
  2. Find “SMS Agent Host”
  3. Open it and click “Stop”

Also run shutdown -a  to make sure your computer does not restart itself.

The shutdown notification should go away. It might return after a while, but you repeat the steps above over and over.


Posted in Tips | Tagged , , , , , | 39 Comments

Internet Explorer: ScriptImports is undefined

Today I spent way too much time on hunting down a bug that occurred in Internet Explorer 11 running our intranet solution on SharePoint Online / 2016. The problem showed itself by throwing the following error in the console:

SCRIPT5009: ‘ScriptImports’ is undefined
File: eval code (453), Line: 37, Column: 29

The referenced “file” pointed to some internal IE code dealing with Ajax calls. After this error had occurred, other (all?) Ajax calls broke until the page reloaded.

I finally tracked it down to happening when clicking a link with an inline JavaScript handler:

<a href="javascript:void(0)" onclick="javascript:myFunction();">Run myFunction</a>

Nothing special at fist sight, but notice href="javascript:void(0)"  that is supposed to simply stop the default browser action when clicking the link. I’ve seend this before and have assumed it is a proper way to do things. Turns out it’s not! Removing it solved the problem. Here are two alternatives that work:

<a href="#" onclick="javascript:myFunction();">Run myFunction</a>


<a href="javascript:return false;" onclick="javascript:myFunction();">Run myFunction</a>

Posted in Development | Tagged , , , , , | Leave a comment

Beware this limitation when using SharePoint Image Renditions

With image renditions you can specify a pixel size when requesting an image, and SharePoint will deliver the image scaled down to this size for you. This is great, because you don’t have to worry about your users pulling full size pictures from their gigapixel cameras when publishing content. Or do you?

I was recently browsing a customer’s SharePoint Online intranet solution and noticed that some images in the news roll-up loaded slowly. Turned out they had been using high resolution stock photos for a few of their news articles. Even though the news roll-up requested a specific image rendition, SharePoint delivered the original, full size image file. The penalty of this is both downloading large files (10MB in this case) and having the browser scale down the image (which is slow and looks bad). I’m sure you can imagine the performance impact this could have on pages such as an intranet start page where you have lots of images.

I investigated this further by scaling an image to various sizes to see what happened. Turns out, at around 6400 pixels width or height, SharePoint suddenly stops delivering a scaled down image rendition and instead just sends the original file. This is true for both SharePoint Online and SharePoint 2016. My recommendation is that even if you use image rendition, user education is still necessary to avoid problems.

Posted in Tips | Tagged , , | 5 Comments

How to backup and restore tables in Azure storage

There is currently no built in solution for backing up tables in Azure Storage, but we can easily do it with the help of a tool called AzCopy which is provided by Microsoft. Below is a PowerShell script I built to simplify the process of backing up and restoring. It’s a two-step rocket: First it enumerates all your tables and saves a CSV-file with their names. Then it uses this file to perform the actual backup (and restore if needed). This way you can easily edit the CSV-file to “configure” what to backup.

This script is also available at my GitHub repo.


Posted in Development, Tutorials | Tagged , , , , , | 1 Comment

Extending the JavaScript console with history recording

The browser JavaScript console is a web developers best friend. Using console.log()  is essential for debugging your web apps. But there are a few annoyances. Two things that bother me for a while are:

  1. Reloading the page clears the console. Yes, there are settings for keeping the log, but personally I prefer to keep this turned off.
  2. Internet Explorer and Edge will only print to the console once the dev tools window has been opened. The console is always empty when opened, so anything you logged before this is lost.

Fortunately JavaScript is a very flexible language. Let’s make the console better!

Design goals:

  • Record all calls to the console’s log() , error() , warn()  and info()  functions.
  • Recall the console history by calling our own console.history()  function.
    • console.history()  shows the console history since the current page load.
    • console.history(true)  shows everything from the current session.

Here is my solution (also available at my GitHub tutorial repo). I have tried to annotate it to explain what is going on.


Posted in Development, Tutorials | Tagged , , , , , | Leave a comment

Solution to Azure AD App not able to use given permissions

A client I’m working with had trouble adding permissions to their Azure Active Directory Application (AAD App). We added application permissions to allow the app to read all users’ full profiles, read directory data and read O365 unified groups, but no matter what we did our code would get an “insufficient privileges” answer back from the Microsoft Graph. We even added a brand new app, but it too had the same problems, indicating that the problem lied deeper than the app permissions.

Reaching out to Microsoft support they clearly had a hard time figuring out what was wrong, but finally their engineers presented the following solution that worked:

  1. Open PowerShell
  2. Connect-MsolService (sign in with a Global Admin account)
  3. Remove-MsolServicePrincipal -ObjectId [GUID] -TenantId [GUID]
  4. Start an InPrivate browsing window
  5. Open:[GUID]&prompt=admin_consent

This is supposed to remove the Service Principal and following the admin consent workflow a new Service Principal should be created and inherit the permissions given to the application object.

I hope this is helpful to someone in the same situation.

Posted in Development | Tagged , , , | Leave a comment