Disable Yammer License in Office 365 Education

Standard

A few weeks ago I wrote a blog post about changing licenses from the Office 365 Education license to the Office 365 Plus Education license.  This PowerShell script will help you to make these changes.

In the last week, further integration of Yammer and Office 365 has accord where we can now disable the Yammer license.

I’ve had many customers ask if there was a way we could just allow teachers and admin staff access to Yammer and we haven’t been able to do that until now.

Below are a set of script that will help you to either remove the Yammer license from all users (doesn’t matter what license they have been assigned), keep the current options they have enabled and then removes the yammer option.  The second script will just remove it from users who have a student license.

Remove Yammer license from all users

#$users = Get-MsolUser -MaxResults 10000 | Select-Object -property UserPrincipalName -ExpandProperty Licenses
foreach ($user in $users){

    $UPN = $user.userprincipalname
    $useraccount = get-msoluser -UserPrincipalName $UPN
    $licensetype = $useraccount.Licenses.accountskuid
    $licensesassigned = $useraccount.Licenses.servicestatus


write-host ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
write-host ~~~~ Now Starting on $UPN ~~~~
write-host "The following licenses are disabled on this account"
                $disabledPlans= @()
        foreach ($line in $licensesassigned) {
                if ($line.ServicePlan.ServiceName -eq "SWAY" -and $line.ProvisioningStatus -eq "Disabled") {Write-Host $line.ServicePlan.ServiceName "Disabled" -BackgroundColor DarkRed}
                if ($line.ServicePlan.ServiceName -eq "SHAREPOINTWAC_EDU" -and $line.ProvisioningStatus -eq "Disabled") {Write-Host $line.ServicePlan.ServiceName "Disabled" -BackgroundColor DarkRed}
                if ($line.ServicePlan.ServiceName -eq "MCOSTANDARD" -and $line.ProvisioningStatus -eq "Disabled") {Write-Host $line.ServicePlan.ServiceName "Disabled" -BackgroundColor DarkRed}
                if ($line.ServicePlan.ServiceName -eq "SHAREPOINTSTANDARD_EDU" -and $line.ProvisioningStatus -eq "Disabled") {Write-Host $line.ServicePlan.ServiceName "Disabled" -BackgroundColor DarkRed}
                if ($line.ServicePlan.ServiceName -eq "EXCHANGE_S_STANDARD" -and $line.ProvisioningStatus -eq "Disabled") {Write-Host $line.ServicePlan.ServiceName "Disabled" -BackgroundColor DarkRed}
                ###############################################

                if ($line.ServicePlan.ServiceName -eq "YAMMER_EDU") { $disabledPlans +="YAMMER_EDU"}
                if ($line.ServicePlan.ServiceName -eq "SWAY" -and $line.ProvisioningStatus -eq "Disabled") { $disabledPlans +="SWAY"}
                if ($line.ServicePlan.ServiceName -eq "SHAREPOINTWAC_EDU" -and $line.ProvisioningStatus -eq "Disabled") { $disabledPlans +="SHAREPOINTWAC_EDU"}
                if ($line.ServicePlan.ServiceName -eq "MCOSTANDARD" -and $line.ProvisioningStatus -eq "Disabled") { $disabledPlans +="MCOSTANDARD"}
                if ($line.ServicePlan.ServiceName -eq "SHAREPOINTSTANDARD_EDU" -and $line.ProvisioningStatus -eq "Disabled") { $disabledPlans +="SHAREPOINTSTANDARD_EDU"}
                if ($line.ServicePlan.ServiceName -eq "EXCHANGE_S_STANDARD" -and $line.ProvisioningStatus -eq "Disabled")  {$disabledPlans +="EXCHANGE_S_STANDARD"}

        }


    Set-MsolUserLicense -UserPrincipalName $UPN -RemoveLicenses $licensetype
        $License = New-MsolLicenseOptions -AccountSkuId $licensetype -DisabledPlans $disabledPlans;
 $info = Set-MsolUserLicense -UserPrincipalName $UPN -AddLicenses $licensetype -LicenseOptions $License

  write-host "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
    write-host ""
    
}

 

Remove Yammer from Student assigned accounts only

$users = Get-MsolUser -MaxResults 10000 | Select-Object -property UserPrincipalName -ExpandProperty Licenses
foreach ($user in $users){

    $UPN = $user.UserPrincipalName
    $useraccount = get-msoluser -UserPrincipalName $UPN
    $licensetype = $useraccount.Licenses.accountskuid
    $licensesassigned = $useraccount.Licenses.servicestatus

write-host ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
write-host ~~~~ Now Starting on $UPN ~~~~
write-host "The following licenses are disabled on this account"
                $disabledPlans= @()
        foreach ($line in $licensesassigned) {
                if ($line.ServicePlan.ServiceName -eq "SWAY" -and $line.ProvisioningStatus -eq "Disabled") {Write-Host $line.ServicePlan.ServiceName "Disabled" -BackgroundColor DarkRed}
                if ($line.ServicePlan.ServiceName -eq "SHAREPOINTWAC_EDU" -and $line.ProvisioningStatus -eq "Disabled") {Write-Host $line.ServicePlan.ServiceName "Disabled" -BackgroundColor DarkRed}
                if ($line.ServicePlan.ServiceName -eq "MCOSTANDARD" -and $line.ProvisioningStatus -eq "Disabled") {Write-Host $line.ServicePlan.ServiceName "Disabled" -BackgroundColor DarkRed}
                if ($line.ServicePlan.ServiceName -eq "SHAREPOINTSTANDARD_EDU" -and $line.ProvisioningStatus -eq "Disabled") {Write-Host $line.ServicePlan.ServiceName "Disabled" -BackgroundColor DarkRed}
                if ($line.ServicePlan.ServiceName -eq "EXCHANGE_S_STANDARD" -and $line.ProvisioningStatus -eq "Disabled") {Write-Host $line.ServicePlan.ServiceName "Disabled" -BackgroundColor DarkRed}
                ###############################################


                if ($line.ServicePlan.ServiceName -eq "SWAY" -and $line.ProvisioningStatus -eq "Disabled") { $disabledPlans +="SWAY"}
                if ($line.ServicePlan.ServiceName -eq "SHAREPOINTWAC_EDU" -and $line.ProvisioningStatus -eq "Disabled") { $disabledPlans +="SHAREPOINTWAC_EDU"}
                if ($line.ServicePlan.ServiceName -eq "MCOSTANDARD" -and $line.ProvisioningStatus -eq "Disabled") { $disabledPlans +="MCOSTANDARD"}
                if ($line.ServicePlan.ServiceName -eq "SHAREPOINTSTANDARD_EDU" -and $line.ProvisioningStatus -eq "Disabled") { $disabledPlans +="SHAREPOINTSTANDARD_EDU"}
                if ($line.ServicePlan.ServiceName -eq "EXCHANGE_S_STANDARD" -and $line.ProvisioningStatus -eq "Disabled")  {$disabledPlans +="EXCHANGE_S_STANDARD"}

        }

    Set-MsolUserLicense -UserPrincipalName $UPN -RemoveLicenses $licensetype

    if ($licensetype -like "*STUDENT*"){
            write-host "This user has a student license"
            $FullFrictionFreeLicense = Get-MsolAccountSku | Where-Object {$_.AccountSKUID -like "*STANDARDWOFFPACK_IW_STUDENT*"}
                                            }
    
    if ($licensetype -like "*FACULTY*") {
            write-host "This user has a faculty license"
            $FullFrictionFreeLicense = Get-MsolAccountSku | Where-Object {$_.AccountSKUID -like "*STANDARDWOFFPACK_IW_FACULTY*"}
                                            }
        
    $License = New-MsolLicenseOptions -AccountSkuId $FullFrictionFreeLicense.AccountSkuId -DisabledPlans $disabledPlans;
 $info = Set-MsolUserLicense -UserPrincipalName $UPN -AddLicenses $FullFrictionFreeLicense.AccountSkuId -LicenseOptions $License
  
  ###test

      $testuseraccount = get-msoluser -UserPrincipalName $UPN
    $testlicensetype = $useraccount.Licenses.accountskuid

    if ($testlicensetype -like "*STANDARDWOFFPACK_IW*") { write-host "Success" -BackgroundColor DarkGreen} ELSE {write-host "FAILED" -BackgroundColor Red}

  
    write-host "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
    write-host ""
}

 

Change All Faculty and Students to Office 365 Edu Plus Licenses

Standard

We have seen many changes to Office 365 but Office 365 Education changes even more as Microsoft given more free services to education establishment worldwide.  Back in September 2015, Microsoft gave some of the E3 features to Office 365 and renamed the license from Office 365 E1 for Student (Faculty) to Office 365 Education for Student (Faculty), still free.

During the announcement around making the Office client available through Office 365, better known as Office 365 Pro Plus, Microsoft made it easy for students and teachers to get the software by asking for their email address and check their licensing records to then give them Office 365 Education.

You may have noticed this added over 1.5 million licenses to your tenant allowing you to change all your users to this new license.  This license is now called the Office 365 Education PLUS for Student (Faculty) license.

So you now have the ability to give all your students and staff Office 365 Pro Plus as you have these licenses added to your tenant, but to assign them to each of your users is time consuming and you may already have disabled other plans such as Skype for Business.  Something that can be time consuming.

The below script runs and checks to see what services are assigned to each user, removes the current license and then add the Plus license with the same disabled features as previous.  It will also check to see if their currently have a faculty or student license and ensure the right one is licensed.

You will need the Azure AD PowerShell install to make this run and also connected to your tenant (Connect-MSOLService).

$users = Get-MsolUser -MaxResults 10000 | Select-Object -property UserPrincipalName -ExpandProperty Licenses
foreach ($user in $users){

$UPN = $user.userprincipalname
$useraccount = get-msoluser -UserPrincipalName $UPN
$licensetype = $useraccount.Licenses.accountskuid
$licensesassigned = $useraccount.Licenses.servicestatus

write-host ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
write-host ~~~~ Now Starting on $UPN ~~~~
write-host "The following licenses are disabled on this account"
$disabledPlans= @()
foreach ($line in $licensesassigned) {
if ($line.ServicePlan.ServiceName -eq "SWAY" -and $line.ProvisioningStatus -eq "Disabled") {Write-Host $line.ServicePlan.ServiceName "Disabled" -BackgroundColor DarkRed}
if ($line.ServicePlan.ServiceName -eq "SHAREPOINTWAC_EDU" -and $line.ProvisioningStatus -eq "Disabled") {Write-Host $line.ServicePlan.ServiceName "Disabled" -BackgroundColor DarkRed}
if ($line.ServicePlan.ServiceName -eq "MCOSTANDARD" -and $line.ProvisioningStatus -eq "Disabled") {Write-Host $line.ServicePlan.ServiceName "Disabled" -BackgroundColor DarkRed}
if ($line.ServicePlan.ServiceName -eq "SHAREPOINTSTANDARD_EDU" -and $line.ProvisioningStatus -eq "Disabled") {Write-Host $line.ServicePlan.ServiceName "Disabled" -BackgroundColor DarkRed}
if ($line.ServicePlan.ServiceName -eq "EXCHANGE_S_STANDARD" -and $line.ProvisioningStatus -eq "Disabled") {Write-Host $line.ServicePlan.ServiceName "Disabled" -BackgroundColor DarkRed}
###############################################
if ($line.ServicePlan.ServiceName -eq "SWAY" -and $line.ProvisioningStatus -eq "Disabled") { $disabledPlans +="SWAY"}
if ($line.ServicePlan.ServiceName -eq "SHAREPOINTWAC_EDU" -and $line.ProvisioningStatus -eq "Disabled") { $disabledPlans +="SHAREPOINTWAC_EDU"}
if ($line.ServicePlan.ServiceName -eq "MCOSTANDARD" -and $line.ProvisioningStatus -eq "Disabled") { $disabledPlans +="MCOSTANDARD"}
if ($line.ServicePlan.ServiceName -eq "SHAREPOINTSTANDARD_EDU" -and $line.ProvisioningStatus -eq "Disabled") { $disabledPlans +="SHAREPOINTSTANDARD_EDU"}
if ($line.ServicePlan.ServiceName -eq "EXCHANGE_S_STANDARD" -and $line.ProvisioningStatus -eq "Disabled") {$disabledPlans +="EXCHANGE_S_STANDARD"}

}

Set-MsolUserLicense -UserPrincipalName $UPN -RemoveLicenses $licensetype

if ($licensetype -like "*STUDENT*"){
write-host "This user has a student license"
$FullFrictionFreeLicense = Get-MsolAccountSku | Where-Object {$_.AccountSKUID -like "*STANDARDWOFFPACK_IW_STUDENT*"}
}

if ($licensetype -like "*FACULTY*") {
write-host "This user has a faculty license"
$FullFrictionFreeLicense = Get-MsolAccountSku | Where-Object {$_.AccountSKUID -like "*STANDARDWOFFPACK_IW_FACULTY*"}
}

$License = New-MsolLicenseOptions -AccountSkuId $FullFrictionFreeLicense.AccountSkuId -DisabledPlans $disabledPlans;
$info = Set-MsolUserLicense -UserPrincipalName $UPN -AddLicenses $FullFrictionFreeLicense.AccountSkuId -LicenseOptions $License

###test

$testuseraccount = get-msoluser -UserPrincipalName $UPN
$testlicensetype = $useraccount.Licenses.accountskuid

if ($testlicensetype -like "*STANDARDWOFFPACK_IW*") { write-host "Success" -BackgroundColor DarkGreen} ELSE {write-host "FAILED" -BackgroundColor Red}
write-host "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
write-host ""
}

 

CSOM + PowerShell: Setting Theme on Site

Standard

If you are looking to change the theme of your SharePoint 2013 and SharePoint Online site you can do this through CSOM.

Having connected to your environment you can run the below script that will change the theme to the Colour Palette to you have create – see this blog post on creating colour palettes

$web.ApplyTheme( “/_catalogs/theme/15/NewColourPalette.spcolor”, “/_catalogs/theme/15/NewFont.spfont”, “/_catalogs/theme/theme/15/BackGroundImage.jpg” , $True)
$web.update()
$ctx.Load($web)
$ctx.ExecuteQuery()

 

To see how to connect to your environment so the following blog post – Connecting to SharePoint Online through CSOM and PowerShell

CSOM-of-the-Day

Deactivate Sandbox Solution with PowerShell in Office 365

Standard

In recent days Microsoft have released a Visual Studio solution which allows you to control SharePoint Online sandbox solutions.

The solutions builds a DLL file which can be imported as a PowerShell module and then you can use it to Upload, Activate, Deactivate and Delete solutions from a SharePoint Online site collection.

The provided documentation is great however during my own testing I found that solutions were not getting deactivated in my SharePoint Online 2010 site collections.

You will most likely find your 2010 site collection is actually in SharePoint 2013 version (15.0+) however if you use the -environment “MSO_2010” presents an error.  If you change this to -environment “MSO_2013” you will find it works even though you site collection appears to be in 2010.

Click here to download the solution from the Microsoft code website.  You will have to Build the solution to get the DLL as the one from the download does not work.  Alternatively you can download it from here.

Happy PowerShell’ing

Import Module

Import-Module “c:Contoso.Solution.Cmdlets.dll”

Upload Solution

upload-solution -username “admin@xyz.onmicrosoft.com” -password “XXXX” -siteurl “https://xyz.sharepoint.com” -solutionfilepath “C:\Example.wsp” -environment MSO_2013

Activate Solution

activate-solution -username “admin@xyz.onmicrosoft.com” -password “xxxx” -siteurl “https://xyz.sharepoint.com” -solutionid “5BC8D9A8-AE5A-4CF8-8D25-03B239818193” -environment MSO_2013

Deactivate Solution

deactivate-solution -username “admin@xyz.onmicrosoft.com” -password “xxxx” -siteurl “https://xyz.sharepoint.com” -solutionid “5BC8D9A8-AE5A-4CF8-8D25-03B239818193” -environment MSO_2013

Delete Solution

delete-solution -username “admin@xyz.onmicrosoft.com” -password “xxxx” -siteurl “https://xyz.sharepoint.com” -solutionid “5BC8D9A8-AE5A-4CF8-8D25-03B239818193” -environment MSO_2013

1stImageBlogPost---Extended

Get Site Template ID for Custom Site Templates

Standard

I have been spending a lot of time in Powershell over the last week and have learnt a lot about how this great tool can customise SharePoint 2010.

As part of the project we have created a set of custom site templates and I had to create a new school with several custom site templates.

In a previous post I have listed the out of the box site templates which you might need to create a site through powershell but now you need to create one with a custom template ID.

To get this ID you need to create a PowerShell file (.ps1) with the below script.

$url = “http://sp2010/”
$site= new-Object Microsoft.SharePoint.SPSite($url )
$loc= [System.Int32]::Parse(1033)
$templates= $site.GetWebTemplates($loc)
foreach ($child in $templates){ write-host $child.Name ”  ” $child.Title}

You will then see the a list of all different IDs and names.

image

Create SharePoint Site using Powershell

Standard

You should becoming increasingly familiar with PowerShell and SharePoint 2010 now and you are building so great scripts to help manage your environment.

A few weeks ago I had the requirement to create over 3000 sites with the site names stored in a Excel spreadsheet.

image

But first we need to understand how to create a site using Powershell.  The special command is new-spweb which only has 1 requirement and that is the URL of the site but there are several other parameters that you should use when creating a site with Powershell.

Parameter Information
-url Where do you want to create the new site which includes the URL of the new site
-template Add the template number to use the Basic Site or Publishing Site.  A full list here
SharePoint 2010 Site Templates
-name Display name of the site
-AddToTopNav Do you want the site to display in the top navigation bar?
-UseParentTopNav Do you want the site to display in the parent navigation?

Learning PowerShell: Part 2

Standard

In my previous post I looked at some of the very basics of PowerShell but now its time to create some scripts.

I’m always building new virtual machines on my laptop and I’m fed up having to add IP Address and how I have click so many times to add this and type in a new computer name.

So thought PowerShell can solve this problem for me.

The first issue I had was that there are some security issues to stop you from just running scripts that change computer settings like this.  First run the command before to change the execution policy on your computer.  You then have to confirm that you want to do this.

   1: Set-ExecutionPolicy Unrestricted

image

Firstly I want the script to prompt me what computer name I want and then the different IP settings for the server.  I type in $NewName=Read-Host “Computer Name”.  If we break this down a little you’ll see the different settings you’ll need for your script.

The $NewName is your variable to store what you have typed.  Later in your script where you type $NewName it will be replaced with what you type when you were prompted.  Where you can see “Computer Name” is the text that will show up on screen as the descriptions of your prompt.

If we run this simple command below it will prompt me for the new computer name and then display it on the screen

   1: $NewName=Read-Host "Computer Name"

   2: echo $NewName

image

Here on the 3rd line you can see it has displayed what we typed when prompted.

To actually change the computer name we need to run 2 lines of PowerShell in our script.

Have a look at the code below and you will notice on the second line it has $newname which is from the prompt earlier.

   1: $ComputerInfo = Get-WmiObject -Class Win32_ComputerSystem

   2: $ComputerInfo.Rename($NewName)

When adding this to what we already have we the script will change the computer name to what we were prompted.  The computer will then change name after a restart.

A new command line tool that I have started to use in recent weeks since I started looking at Window Server 2008 Core is netsh.exe.  Netsh allows you to control the behaviour of the networking on your windows device.  I change change the IP Address, change the name from Local Area Connection to what ever you want it to be.  I can also change the firewall settings as well.

We’re going to add a few more prompts for the IP Address, Subnet Mask, Default Gateway and DNS Server and these will be used during the netsh commands.

All together we have 3 netsh commands in this script, one will set the IP, Subnet and Default Gateway, one will set the DNS Server and other will turn the firewall off (in my development areas I turn my firewall off).

Below is the full script to change the computer and it will have ask for prompts and add the right information into the script.

   1: #Prompts

   2:

   3: $NewName=Read-Host "Computer Name"

   4:

   5: $addres=Read-Host "Please state the IP Address"

   6: $subnet=Read-Host "Subnet"

   7: $defag=Read-Host "Default Gateway"

   8: $dns=Read-Host "DNS"

   9:

  10: #Change Computer Name

  11:

  12: $ComputerInfo = Get-WmiObject -Class Win32_ComputerSystem

  13: $ComputerInfo.Rename($NewName)

  14:

  15:

  16: #IP Address

  17:

  18: netsh int ipv4 set address "Local Area Connection" static address=$addres mask=$subnet gateway=$defag gw=1

  19: netsh int ipv4 set dnsserver "Local Area Connection" static $dns

  20:

  21: netsh firewall set opmode disable

  22:

  23: restart-computer

Learning PowerShell: Part 1

Standard

I’ve been meaning to learn PowerShell for some time now as its an important of SharePoint 2010 and I thought I better get started.  In SharePoint 2010 even if you wanted to try and avoid PowerShell you won’t be able to as this is the best way to patch your farm.

Over the years I have created several batch scripts from collecting computer programs and services installed on all machines on a network, creating all my default Active Directory accounts and a user creation script that adds user to the correct Organisation Unit and AD Group which then allows the user to access the correct sites within SharePoint.  I love these scripts and I love batch files as they have always done what I wanted them to do at the time. But PowerShell is here now and its a new learning curve and I need to learn it.

I’ve played around with it a little before when I’ve mailbox enabled an Active Directory username and it has returned the PowerShell command but that’s cheating as it has already given me the code.  I’m not going to learn it by copying and pasting, I need to work out how to do things and get error messages, do some research and then get the results I want.

Windows PowerShell is  an extensible automation engine from Microsoft, consisting of a command-line shell and associated scripting language (Source: Wikipedia).  It now comes standard with Windows Server 2008 R2 and Windows 7.  There are some built in command that manage the operating system but there are also modules you can add to add command and script against that product.

To import a module you need to know the module name for example Active Directory is activedirectory and to use the Windows Server Manager Console you need to use servermanager

   1: import-module activedirectory

   2: import-module servermanager

In Windows 7 you also get Windows PowerShell ISE which stands for Integrated Scripting Environment which is a great way to write scripts and see what is going on with errors.  You can run it in this environment to test the script.

image

As you can see in the middle section of this screenshot when I tried to import the servermanager console returned an error mainly because the module can not be found on this machine.

There are some command line commands that still work in PowerShell, like changing directory is still cd %foldername% or to create a new folder is still md *newnameoffolder*.

image

There are new commands to do these as well, like change directory is  set-location and create a new folder is  new-item

image

To me, I prefer the older version – its quicker and I already know this and when it comes to creating a script I still use the older commands.  If you think you are going to have to learn everything in powershell, don’t worry there are some old commands that still work ;-).

The old style batch command were easy to create and they are the same in PowerShell.  Instead of using the .bat extension you have a new one called .ps1.  Microsoft have really helped with editing the file.  If you want to edit the file double click on the file and it will open up in notepad and if you want to run the command you right click on the object and then click Run with PowerShell.  The number of times I’ve gone to edit my batch script and I’ve run it by mistake is not worth counting.  Now I can’t make this mistake again.

image

I had to do some research for the next part.  I’m in my PowerShell console and I can’t load my .ps1 script.  I type in the file name and it just doesn’t run.  To run your powershell command type in .file.ps1 and it will run it for you.

image

I’ll keep you updated on how the learning is going.  My objective is to install Active Directory, SQL, Exchange and SharePoint all through PowerShell.