Skip to content

Instantly share code, notes, and snippets.

@pkskelly
Last active August 13, 2019 20:47
Show Gist options
  • Save pkskelly/857a4f9d79a9b29e2562fbf22e564356 to your computer and use it in GitHub Desktop.
Save pkskelly/857a4f9d79a9b29e2562fbf22e564356 to your computer and use it in GitHub Desktop.
Shell script using Office 365 CLI v2 to group enable and connect a MS Team to an existing SharePoint Online classic team site.
#!/usr/bin/env bash
help() {
echo
echo " ****************************************************************"
echo " ** Teamify Classic Site "
echo " ** "
echo " ** Simple script to Groupify and Teamify a SharePoint Online Classic site"
echo " ** "
echo " ** Usage: ./teamify-classicsite.sh -s|--siteUrl [classic site url] -a|--alias [alias] -d|--description [description]"
echo " ** "
echo " ** -s|--siteUrl [classic site url] - url of the classic site to move"
echo " ** -a|--alias [alias] - alias to be used for the amail alais of the Office 365 group"
echo " ** -d|--description [description] - description of the group"
echo " ** "
echo " ** Example: "
echo " ** ./teamify-classicsite.sh -s https://contoso.sharepoint.com/sites/classicsite -a 'groupifiedclassicsite' -d 'Groupified Site'"
echo " ** "
echo " ** "
echo " ****************************************************************"
}
CLASSIC_URL=""
ALIAS=""
DESCRIPTION=""
PAUSE=120
# script arguments
while [ $# -gt 0 ]; do
case $1 in
-s|--siteUrl)
shift
CLASSIC_URL=$1
;;
-a|--alias)
shift
ALIAS=$1
;;
-d|--description)
shift
DESCRIPTION=$1
;;
-h|--help)
help
exit
;;
*)
echo "Invalid argument $1"
help
exit 1
esac
shift
done
# Check prerequisite for Office 365 CLI
echo 'Checking script prerequisites...'
set +e
echo 'Checking for jq...'
_=$(command -v jq);
if [ "$?" != "0" ]; then
echo 'ERROR'
echo
echo "You don't seem to have jq installed."
echo "See https://stedolan.github.io/jq/ for installation and usage."
exit 1
fi;
echo "OK"
echo 'Checking for Office 365 CLI...'
_=$(command -v o365);
if [ "$?" != "0" ]; then
echo 'ERROR'
echo
echo "You don't seem to have the Office 365 CLI v2 installed."
echo "See https://pnp.github.io/office365-cli/ for installation and usage."
exit 1
fi;
echo "OK"
set -e
if [ -z "$CLASSIC_URL" ]; then
help
exit 1
fi
if [ -z "$ALIAS" ]; then
help
exit 1
fi
if [ -z "$DESCRIPTION" ]; then
help
exit 1
fi
existingGroup=$(o365 spo site get --url $CLASSIC_URL --output json | jq -r '.GroupId')
if [[ "$existingGroup" == "00000000-0000-0000-0000-000000000000" ]]; then
echo "Creating Group..."
# Other options are avaiable for groupify command. See docs or help for all details.
groupId=$(o365 spo site groupify --siteUrl "$CLASSIC_URL" --alias "$ALIAS" --displayName "$DESCRIPTION" --isPublic --output json | jq -r '.GroupId')
if [ -z "$groupId" ]; then
echo "Error! Group ID is null ($groupId). Ensure ${CLASSIC_URL} exists"
exit 1
fi
echo "Creatied Group with ID : $groupId"
#sleep for a few seconds for graph to create
echo "Sleeping for $PAUSE seconds to await groupId $groupId availability."
sleep $PAUSE
# # Create the Team for the group
o365 teams team add --groupId $groupId
echo "Completed Team-ifying ${CLASSIC_URL} with Group ID $groupId."
else
echo "Error! GroupId is ${existingGroup}. Ensure ${CLASSIC_URL} exists and is not already groupified!"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment