question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] CLI M365 samples - `m365 status` invalid condition check

See original GitHub issue

When we use CLI for Microsoft 365 within PowerShell we shouldn’t forget to convert our output to an object. Most samples start off by doing a m365 status check to see if they are still logged in to their Microsoft 365 environment. Which looks something like this.

$m365Status = m365 status
if ($m365Status -eq "Logged Out") {
    m365 login
}

The if condition here will always be false because we aren’t converting the output of m365 status to an object.

afbeelding

To solve this we need to use ConvertFrom-Json after the status command. Then the login logic would look like this.

$m365Status = m365 status | ConvertFrom-Json
if ($m365Status -eq "Logged Out") {
    m365 login
}

This will ensure that our output is converted to a usable variable within PowerShell.

afbeelding

This issue applies to the following samples:

  • aad-analyze-users-hibp
  • aad-delete-m365-groups-and-sharepoint-sites
  • aad-replace-membership-of-selected-groups
  • aad-replace-owner-with-a-different-one
  • bulk-undelete-from-recyclebin
  • create-comm-sites-specific-locale
  • flow-runs-day-summary
  • flow-runs-status-list-dashboard
  • generate-markdown-lcids
  • get-all-site-collections-subwebs
  • planner-migration-spo-list
  • remove-delete-option-library
  • report-private-teams-excel
  • spo-add-document-library-webpart-to-page
  • spo-add-multiple-lists-in-multiple-sites
  • spo-export-sharepoint-list-items-to-csv
  • spo-add-site-design-with-custom-list
  • spo-add-tenant-theme
  • spo-cleanup-site-column-usage
  • spo-copy-files-to-another-library
  • spo-export-data-to-sharepoint-lists
  • spo-export-site-usage-reports
  • spo-generate-demo-events
  • spo-get-all-apps-from-appcatalog
  • spo-get-lists-libraries-item-count-permissions
  • spo-group-permission-report
  • spo-list-items-large-lists
  • spo-list-items-with-caml-query
  • spo-list-site-collection-lists
  • spo-list-site-collection-owners
  • spo-list-site-externalusers
  • spo-recyclebin-items-to-csv
  • spo-remove-large-library
  • spo-replace-site-collection-admin
  • spo-set-home-site
  • spo-setup-example-site
  • spo-upload-local-files-and-folder
  • teams-add-bulk-users-teams
  • teams-create-team-and-add-members-and-owners
  • teams-teams-export-teams-information
  • teams-full-report
  • teams-install-personal-app
  • teams-list-all-tabs-teams
  • teams-list-all-teammembers-teams
  • teams-list-teams-owners-and-members
  • teams-remove-personal-app
  • teams-share-socialchampion
  • user-language-for-site

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
pkbullockcommented, Jun 5, 2022

Another method (after checking to see how widespread this is) is using “-Match” instead of “-eq”. Would this be an easier change?

image

I saw this btw in an article I read recently: https://techcommunity.microsoft.com/t5/microsoft-365-pnp-blog/monitor-and-notify-m365-health-using-cli-for-microsoft-365/ba-p/3000703

Your call. 😊

1reaction
Jwaegebaertcommented, Jun 7, 2022

Good point to check the CLI for M365 version within the sample.json files. The default output change happened as of v4. I do think it is interesting to keep the last tested version of the sample. If we use the -match comparison, as @pkbullock suggested, we capture all the output types. With this, we won’t need to update the version of CLI for M365.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bug report: Invalid option in Examples for "m365 file ... - GitHub
Description The m365 file list command examples have invalid option specified as folder, instead it should be folderUrl Steps to reproduce Execute the ......
Read more >
Troubleshooting sign-in problems with Conditional Access
The information in this article can be used to troubleshoot unexpected sign-in outcomes related to Conditional Access using error messages ...
Read more >
Log in to Microsoft 365 - CLI for Microsoft 365
Following section explains how you can log in and check the Microsoft 365 login status. Microsoft 365 services¶. Using the CLI for Microsoft...
Read more >
Monitor and Notify M365 health using CLI for Microsoft 365
Solution. In this blog, I am showing a way where you can schedule a script that will check the status of your tenant....
Read more >
Configure Microsoft 365 with Secure Email - Cisco
Cisco Secure Email Cloud Gateway > Command Line Interface (CLI) Access ... Microsoft provides Default criteria to search with, for example, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found