Last active
February 10, 2026 16:43
-
-
Save ahhh/c1066198ca5700fa4e3e774a2a8230b5 to your computer and use it in GitHub Desktop.
quick script to see if a domain is being managed / federated on ms365
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| domain="${1:?usage: $0 domain.com [username]}" | |
| user="${2:-}" | |
| # If username is blank or unset, default to "admin" | |
| [[ -z "$user" ]] && user="admin" | |
| # Grab Results | |
| url="https://login.microsoftonline.com/getuserrealm.srf?login=${user}@${domain}&xml=1" | |
| xml="$(curl -fsSL "$url")" | |
| get() { sed -n "s:.*<$1>\\(.*\\)</$1>.*:\\1:p" <<<"$xml" | head -n1; } | |
| attr(){ sed -n "s:.*$1=\"\\([^\"]*\\)\".*:\\1:p" <<<"$xml" | head -n1; } | |
| # Setup Colors | |
| # ANSI | |
| G=$'\033[0;32m'; R=$'\033[0;31m'; Y=$'\033[0;33m'; B=$'\033[1m'; N=$'\033[0m' | |
| # Inline color wrappers | |
| okfail() { [[ "$1" == "true" ]] && printf "%s%s%s" "$G" "$1" "$N" || printf "%s%s%s" "$R" "$1" "$N"; } | |
| nscol() { [[ "$1" == "Managed" ]] && printf "%s%s%s" "$G" "$1" "$N" || ([[ "$1" == "Federated" ]] && printf "%s%s%s" "$Y" "$1" "$N" || printf "%s" "$1"); } | |
| tfcol() { [[ "$1" == "true" ]] && printf "%s%s%s" "$Y" "$1" "$N" || printf "%s%s%s" "$G" "$1" "$N"; } | |
| # Get Results | |
| success="$(attr Success)" | |
| nstype="$(get NameSpaceType)" | |
| fed="$(get IsFederatedNS)" | |
| # Force failure if namespace is Unknown | |
| [[ "$nstype" == "Unknown" ]] && success="false" | |
| # Print Results | |
| printf "${B}User:${N} %s\n" "$user" | |
| printf "${B}Success:${N} %s\n" "$(okfail "$success")" | |
| printf "${B}Domain:${N} %s\n" "$(get DomainName)" | |
| printf "${B}NameSpaceType:${N} %s\n" "$(nscol "$nstype")" | |
| printf "${B}IsFederatedNS:${N} %s\n" "$(tfcol "$fed")" | |
| printf "${B}Brand:${N} %s\n" "$(get FederationBrandName)" | |
| printf "${B}CloudInstance:${N} %s\n" "$(get CloudInstanceName)" | |
| printf "${B}IssuerUri:${N} %s\n" "$(get CloudInstanceIssuerUri)" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment