Change/Add Office 365 Group Email using Office 365 PowerShell


$Creds = Get-Credential -Message “Please enter Office 365 Global Admin Credentials”
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Creds -Authentication Basic -AllowRedirection
Import-PSSession $Session

$AllGroups = Get-UnifiedGroup -Filter *

#Getting first group just for checking. 
$FirstGroup = Get-UnifiedGroup -Identity $AllGroups[0].Id

#Syntax

#{Add=”<Type>:<emailaddress1>”,”<Type>:<emailaddress2>”,…; Remove=”<Type>:<emailaddress2>”,”<Type>:<emailaddress2>”}.

$EmailAdded = @{Add=”smtp:bigwigstest@sharepointmvp.onmicrosoft.com”}
Set-UnifiedGroup -Identity $FirstGroup.Id -EmailAddresses $EmailAdded -Verbose

Advertisements

Export SharePoint Online Site Collection Information to SQL Server


There is easy way to collection reports when you have large number of Site collections on SharePoint Online.  The new Admin center will help but sometime customers have external system where they want to review and control site collection information.  The script below will iterate site collections, sites, lists and permissions and store them to a SQL Server Database.  It uses SharePoint Online Client components so you must downloaded and install the latest version of client Components from PowerShell Gallary using the method below

https://www.nuget.org/packages/Microsoft.SharePointOnline.CSOM

Download nuget command line (I saved it to c:\nuget)

    Command Prompt: 

    1. cd C:\nuget
    2. nuget.exe install Microsoft.SharePointOnline.CSOM

    Powershell (elevated)

    1. cd C:\nuget
    2. Install-Package -Name ‘Microsoft.SharePointOnline.CSOM’ -Source .\Microsoft.SharePointOnline.CSOM.16.1.8412.1200
    3. Import-Module ‘C:\nuget\Microsoft.SharePointOnline.CSOM.16.1.8412.1200\lib\net45\Microsoft.SharePoint.Client.dll

    https://gallery.technet.microsoft.com/Export-SharePoint-Online-27920e67

    Provision Multiple Microsoft Teams using Microsoft Excel and PowerShell


    The script below provides the ability to create a Microsoft Team using Microsoft Teams PowerShell Module.  You must install the latest version of the module from PowerShell Gallery.  The script uses an Excel file as input.  For Authentication you have the option to use Azure Active Directory App (Preview) with certificate authentication or simply cloud based authentication using local credentials.  

    You must login to Azure Active Directory to create the Azure Active Directory Application inside preview.  Then create a self signed certificate and upload that to Azure AD App.  You can then use the thumbprint to connect to Microsoft Teams Module.  You must also specify the Current user as Owner as App based auth requires at least one Team Owner.

    You can install both the Modules using the script below.

    Install-Module ImportExcel -Force -Verbose
    Install-Module MicrosoftTeams -Force –Verbose

    You can test the ExcelImport module using the basic script below.

    $ImportPath = “C:\temp\CreateTeam-Basic.xlsx”
    $Teams = Import-Excel -Path $ImportPath -WorksheetName “Teams”
    $Owers = Import-Excel -Path $ImportPath -WorksheetName “Owners”
    $Members = Import-Excel -Path $ImportPath -WorksheetName “Members”
    $Channels = Import-Excel -Path $ImportPath -WorksheetName “Channels”
    $Tabs = Import-Excel -Path $ImportPath -WorksheetName “Tabs”

    image

    https://gallery.technet.microsoft.com/Provision-Multiple-Teams-4ef05794

    Create Microsoft Team using CSV


    The script below provides the ability to create a Microsoft Team using Microsoft Teams PowerShell Module.  You must install the latest version of the module from PowerShell Gallery.  The script uses a CSV File as input.  For Authentication you have the option to use Azure Active Directory App (Preview) with certificate authentication or simply cloud based authentication using local credentials.  

    You must login to Azure Active Directory to create the Azure Active Directory Application inside preview.  Then create a self signed certificate and upload that to Azure AD App.  You can then use the thumbprint to connect to Microsoft Teams Module.  You must also specify the Current user as Owner as App based authentication requires at least one Team Owner.

    The script can be downloaded from

    https://gallery.technet.microsoft.com/Create-using-CSV-d8294bc9

    Add Custom Banner to SharePoint Site without changing master page


    Few days ago, I got a question if it is possible to add a banner message to a SharePoint Online or On-premises site without customizing the master page.  They were looking for a way to enable and disable this using the Feature framework so I had to write a feature event receiver to upload the customized master page.  The customer was happy but I was not. 

    I did some research and ended up finding something that makes it lot easier to do such things.  You can do it using Code using the event receiver but I wanted to make sure you do not deploy any server side solution.  The script below using CSOM to get things done.  All you need is the jquery file and the custom js file uploaded to a CDN or SharePoint assets library.  If you are running off the server then you need to deploy SharePoint client side assemblies from Microsoft download center.

    Add-Type -Path “C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll”
    Add-Type -Path “C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll”

    function Add-SPBanner($SiteUrl, $Credentials)
    {
      $context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
      $context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Credentials.UserName,$Credentials.Password)
      $site = $context.Web
      $context.Load($site)
      $context.ExecuteQuery()

      $UserCustomActions = $site.UserCustomActions
      $context.Load($UserCustomActions)
      $context.ExecuteQuery()

      $newAction = $UserCustomActions.Add()
      $newAction.Location = “ScriptLink”
      $newAction.scriptSrc = “~SiteCollection/Style Library/jquery.min.js”
      $newAction.Sequence = 30000
      $newAction.Title= “BannerJquery”
      $newAction.Update()
      $context.ExecuteQuery()

      #add custom js injection action
      $customJSAction = $UserCustomActions.Add()
      $customJSAction.Location = “ScriptLink”
      #reference to JS file
      $customJSAction.ScriptSrc = “~SiteCollection/Style Library/test.js”
      #load it last
      $customJSAction.Title= “BannerJS”
      $customJSAction.Sequence = 30001
      #make the changes
      $customJSAction.Update()
      $context.ExecuteQuery()
     
      Write-Host “Banner has been Added…” -ForegroundColor Green
    }

    function Remove-SPBanner($SiteUrl, $Credentials)

      $context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
      $context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Credentials.UserName,$Credentials.Password)
      $site = $context.Web
      $context.Load($site)
      $context.ExecuteQuery()

      $UserCustomActions = $site.UserCustomActions
      $context.Load($UserCustomActions)
      $context.ExecuteQuery()

      $UserCustomActions | ? Title -Like “Banner*” | Select Title, Sequence
      if($UserCustomActions.Count -gt 0)
      {
        $CA = $UserCustomActions | ? Title -eq “BannerJquery”
        $CA.DeleteObject()

        $CA = $UserCustomActions | ? Title -eq “BannerJS”
        $CA.DeleteObject()
        $context.ExecuteQuery()
        Write-Host “Banner has been Removed…” -ForegroundColor Green
      } 
    }

    $Creds = Get-Credential
    $SiteUrl = “https://sharepointmvp.sharepoint.com”

    Add-SPBanner -SiteUrl $SiteUrl -Credentials $Creds
    Remove-SPBanner -SiteUrl $SiteUrl -Credentials $Creds

    Export SharePoint Online Site Information to CSV


    The script below uses SharePoint Online PowerShell and Client Side Object Model to collect and store site collection information and export it to SQL.  To use this script you must install the SharePoint Online Management Shell and ensure that SharePoint Online Client components are also installed on the machine.  You would need to provide credentials.  The user specified as UserName and possibly the credentials will be added to every site as Site collection Admin.  That is a required step because the user may or may not have detailed information available.

    Script is available below.

    https://gallery.technet.microsoft.com/Export-SharePoint-Online-7e20c575

    Export Office 365 Licenses to CSV


    $Creds = Get-Credential -Message “Please enter Office 365 Global Admin Credentials”
    $InputFile = “C:\temp\UserInput.csv”
    $OutputFile = “C:\temp\UserOutput.csv”

    Connect-MsolService -Credential $Creds

    #$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Creds -Authentication Basic -AllowRedirection
    #Import-PSSession $Session

    $AllUsersData = import-csv -Path $InputFile

    if($AllUsersData)
    {
      $UsersInfo = @()
      foreach($aUser in $AllUsersData)
      {
        $DomainName = “@sharepointmvp.onmicrosoft.com”
        $UserPrincipalName = $aUser.Identity + $DomainName
        Write-Host “Checking Licenses for: $UserPrincipalName” -ForeColor Yellow
        $msolUser = Get-MsolUser -UserPrincipalName $UserPrincipalName -ErrorAction SilentlyContinue
        if($msolUser)
        {
          $Licenses = “None”
          if($msolUser.IsLicensed)
          {
            Write-Host “User $UserPrincipalName is Licensed:” -ForegroundColor Green
            $MSOLUserLicense = $msolUser.Licenses.AccountSkuid
            $Licenses = “”
            for($i = 0; $i -lt $MSOLUserLicense.Count; $i++)
            {
              $Licenses += $msolUser.Licenses[$i].AccountSkuId
              if($i -le $MSOLUserLicense.Count)
              {
                $Licenses += “;`n”
              }
            }
          }
         
          $userObj = New-Object PSObject
          Add-Member -input $userObj noteproperty ‘UserPrincipalName’ $UserPrincipalName
          Add-Member -input $userObj noteproperty ‘Alias’ $aUser.Alias
          Add-Member -input $userObj noteproperty ‘DisplayName’ $aUser.DisplayName
          Add-Member -input $userObj noteproperty ‘Licenses’ $Licenses
          $UsersInfo += $userObj
        }
      }
      $UsersInfo | Export-Csv -Path $OutputFile -NoTypeInformation -Force -Verbose
      Write-host “Output written to $OutputFile”
    }
    start $OutputFile