Skip to content

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

@Jwaegebaert

Description

@Jwaegebaert

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingsample ideaImprovements or additions to samples

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions