Office 365: Working with Groups using PowerShell (I)!

One of the latest additions to Office 365 Groups is the availability of new PowerShell commands that facilitate to do CRUD operations with Groups, add members to a Froup, etc. For example, in the PowerShell Script included as part of this post you can see how to use the Get-UnifiedGroup, New-UnifiedGroup, Set-UnifiedGroup and Remove-UnifiedGroup cmdlets to perform CRUD operations with Groups is made. The script, which you can download from here How to do CRUD operations with Office 365 Groups, is the following one:

############################################################################################################################################

# Script that allows to do work with Office 365 Groups using standard cmdlets for Groups

# Required Parameters: N/A

############################################################################################################################################

 

#Connection to Office 365

$msolCred = Get-Credential

Connect-MsolService -Credential $msolCred

 

#Definition of the function tthat allows to do work with Office 365 Groups using standard cmdlets for Groups

function WorkWith-Office365Groups

{

    param ($sOperationType,$sGroupName,$sNewGroupName)       

    try

    {

        switch ($sOperationType) 

        { 

        "Read" {

            Write-Host "Get all the Office 365 Groups in a tenant" -ForegroundColor Green                        

            Get-UnifiedGroup

            } 

        "Create" {

            Write-Host "Creating a new Office 365 Group" -ForegroundColor Green                 

            New-UnifiedGroup –DisplayName $sGroupName

            }

        "Update" {

            Write-Host "Updating an Office 365 Group" -ForegroundColor Green                 

            #The change in the name can be seen in the O365 Admin Portal

            Set-UnifiedGroup -Identity $sGroupName -DisplayName $sNewGroupName

            } 

        "Remove" {

            Write-Host "Removing an Office 365 Group" -ForegroundColor Green     

            Remove-UnifiedGroup -Identity $sGroupName

            }           

        default {

            Write-Host "Requested Operation not valid!!" -ForegroundColor DarkBlue            

            }

        }

 

    }

    catch [System.Exception]

    {

        write-host -f red $_.Exception.ToString()

    }

}

 

Write-Host "-----------------------------------------------------------"  -foregroundcolor Green

Write-Host "Working with Groups through PowerShell." -foregroundcolor Green

Write-Host "-----------------------------------------------------------"  -foregroundcolor Green

 

$sOperationType="Read"

$sGroupName="O365 PowerShell Group"

WorkWith-Office365Groups -sOperationType $sOperationType -sGroupName $sGroupName

$sOperationType="Create"

WorkWith-Office365Groups -sOperationType $sOperationType -sGroupName $sGroupName

$sOperationType="Update"

$sNewGroupName="Test PS"

WorkWith-Office365Groups -sOperationType $sOperationType -sGroupName $sGroupName -sNewGroupName $sNewGroupName

$sOperationType="Remove"

$sNewGroupName="Test PS"

WorkWith-Office365Groups -sOperationType $sOperationType -sGroupName $sNewGroupName

Once you execute the script in the PowerShell ISE, you will get the following output:

image

Furthermore, when the group is created, an email to the account creating the Group is sent to notifying the user that he is a member of the Group.

image

Nota: In order to use new Office 365 Groups cmdlets, I recommend you to read the following Corey Roth’s post: http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2015/05/12/working-with-office-365-groups-using-powershell.aspx

Un pensamiento en “Office 365: Working with Groups using PowerShell (I)!

  1. Pingback: SharePoint 2013 & Office 365: Resumen de posts (LXVI)! | Pasión por la tecnología...

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s