Skip to content

Instantly share code, notes, and snippets.

@Rhynorater
Created July 1, 2019 18:22
Show Gist options
  • Save Rhynorater/de75bd225b3b00bc638c9ce7a497fbac to your computer and use it in GitHub Desktop.
Save Rhynorater/de75bd225b3b00bc638c9ce7a497fbac to your computer and use it in GitHub Desktop.
Bash script to check if a certain domain is user O365
#!/bin/bash
# Usage checkms.sh
# domains.txt: file with domains on each line to check
# Output: domains that use O365
# -----
# Usage2 checkms.sh domain.com
# Output: domain if uses 0365, nothing if not
if [ "$#" -eq 1 ]; then
x=$(curl -s -k "https://login.microsoftonline.com/getuserrealm.srf?login=username@$1&xml=1" | egrep "Federated|Managed")
if [[ ! -z $x ]]; then
echo "$1"
fi
exit
fi
for i in `cat domains.txt`; do
x=$(curl -s -k "https://login.microsoftonline.com/getuserrealm.srf?login=username@$i&xml=1" | egrep "Federated|Managed")
if [[ ! -z $x ]]; then
echo "$i"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment