My Developer blog

Welcome to my blog, I wanted a place that I could document and share all my development experiences and if it helps people on the way all the better. this is the beginning of the site but I have lots of ideas and will constantly add to it and hopefully blog about it on the way.

Before we start

1 - You will need to have an Office 365 subscription or trail account, you can get set up on an E3 account through this link and hitting the free trail, this will give you access to everything that you need to follow along…

2 - You can use PowerShell, PowerShell ISE or Windows Azure Active Directory model

3 - Whatever you use you may have to run start by using the following command and click on Yes\Yes to all

SET-ExecutionPolicy Unrestricted 

4 - Whatever you use you may have to run start by using the following command and click on Yes\Yes to all

Connecting to Office 365 - please read this post on how to connect to office 365 and it's services.

Connecting

$credentials=get-credential
Import-Module MSOnline
Connect-MsolService
Connect-MSOLService -Credential $credential

Some useful commands

# User Commands

Get-MsolUser
New-MsolUser
Set-MsolUser

# Groups Commands

Get-MsolGroup
New-MsolGroup
Set-MsolGroup

# Licenses Commands

Get-MsolSubscription
New-MsolSubscription
Set-MsolSubscription

# Get Help and examples

Get-help Set-MsolUser -examples
Get-help Set-MsolUser -detailed
Get-help Set-Msoluser -full

Managing Users and Licenses

# Full

New-MsolUser -UserPrincipalName username@domain -DisplayName "FirstName LastName" 
-FirstName "FirstName" -LastName "LastName"

# Example

New-MsolUser -UserPrincipalName dave@funkthedog.com -DisplayName "Dave Cwtch" 
-FirstName "Dave" -LastName "Cwtch"

Create a user and assign them a license

# Full

New-MsolUser -UserPrincipalName dcwtch@funkthedog.com -DisplayName "Dave Cwtch" -FirstName "Dave" -LastName "Cwtch" -UsageLocation "2-Letter location code (GB)"
-licenseAssignment "license"

# Example

New-MsolUser -UserPrincipalName dcwtch@funkthedog.com -DisplayName "Dave Cwtch" -FirstName "Dave" -LastName "Cwtch" -UsageLocation "GB"
-licenseAssignment "Adatum:ENTERPRISEPACK"

Licensing

# You can use the Get-MSOLAccountSku cmdlet to view current licensing

Get-MSOLAccountSku

# You can use the Get-MSOLUser with the -UnlicensedUserOnly to view users without licenses

Get-MsolUser -All | ft displayname, Licenses | Out-File "Filelocation"

# You can use the Get-MSOLAccountSku cmdlet to view current licensing

Get-MSOLAccountSku

## You can use the Get-MSOLUser with the -UnlicensedUserOnly to view users without licenses

# Full

Get-MsolUser -All | ft displayname, Licenses | Out-File "Filelocation"

# Example

Get-MsolUser -All | ft displayname, Licenses | Out-File "C:\userlicenses.csv"

## MSOLUSERLicense enables you to add user licenses and remove

# Full

Set-MsolUserLicense -UserPrincipalName username@domainname -AddLicenses "license"

# Example

Set-MsolUserLicense -UserPrincipalName dcwtch@funkthedog.com -AddLicenses "funkthedog:ENTERPRISEPACK"

## To remove a license

# Full

Set-MsolUserLicense -UserPrincipalName username@domainname -AddLicenses "newlicense" -RemoveLicenses "Oldlicense"

# Example

Set-MsolUserLicense -UserPrincipalName dcwtch@funkthedog.com -AddLicenses "funkthedog:ENTERPRISEPACK" -RemoveLicenses "funkthedog:STANDARDPACK"

# the above would upgrade the user's license from an E1 to an E3 plan

# Assigning a subset of licenses

# The next command returns a list of individual service plans

Get-MsolAccountSku | Where-Object{$_.SkuPartNumber -eq 'ENTERPRISEPACK'} | ForEach-Object {$_.ServiceStatus}

# To assign Office professional Plus, Lync Online, SharePoint Online licenses to a user

$options = New-MsolLicenseOptions -AccountSkuId tenantname:ENTERPRISEPACK
-DisabledPlans YAMMER_ENTERPRISE, RMS_S_ENTERPRISE, SHAREPOINTWAC, EXCHANGE_S_ENTERPRISE

# This saves the resulting license options to the $options variable, which you can then assign to the -LicenseOptions switch

# Full

Set-MsolUserLicense -UserPrincipalName username@domainname -LicenseOptions $options

# Example

Set-MsolUserLicense -UserPrincipalName dcwtch@funkthedog.com  -LicenseOptions $options

Deleting Users

# Full

Remove-MsolUser -UserPrincipalName username@domianname -Force

# Example

Remove-MsolUser -UserPrincipalName dcwtch@funkthedog.com -Force

## remove from recycling bin

# Full

Remove-MsolUser -UserPrincipalName username@domianname -RemoveFromRecycleBin

# Example

Remove-MsolUser -UserPrincipalName dcwtch@funkthedog.com -RemoveFromRecycleBin

Restoring Users

Get-MsolUser -ReturnDeletedUsers

# Note the userprincipleName

Restore-MsolUser -UserPrincipalName userprincipalnameofusertorestore

Creating security groups

# Full

New-MSOLGroup -DisplayName "displayname" - Description "description"

# Example

New-MSOLGroup -DisplayName "Sales" - Description "Sales Team"

## deleteing Security Groups

# Full

Remove-MSOLGroup -ObjectId objectid -Force

# Example

Remove-MSOLGroup -ObjectID 6146df44-dfec-4a88-958b-f5627deb01a -Force

# Note Rather than determing and using the -ObjectID parameter when deleting a group you can use a variable such as $groupId and the Get-MSOLGroup cmdlet with the -searchString parameter

# Adding and removing users from a security group

Get-MsolUser -All | Select UserPrinciplaName, ObjectId

# this will return a list of all users with thier UserPrinciplaName and ObjectId

## to add a user to a security group

# Full

Add-MSOLGroupMember -GroupMemberObjectId groupmemberobjectid -GroupObjectId groupobjectid

# Example

Add-MSOLGroupMember -GroupMemberObjectId 6146df44-dfec-4a88-958b-f5627deb01a -GroupObjectId 6146df44-dfec-uhnn-asdk-f5627jsadasdk

## To Remove a user from a security group

# Full

Remove-MSOLGroupMember -GroupMemberObjectId groupmemberobjectid -GroupObjectId groupobjectid

# Example

Remove-MSOLGroupMember -GroupMemberObjectId 6146df44-dfec-4a88-958b-f5627deb01a -GroupObjectId 6146df44-dfec-uhnn-asdk-f5627jsadasdk

Importing users and groups

NOTE:You will have need to create the users.csv file and add it to the c:drive and example of the file can be downloaded here

# the below will generate random password for each user

Import-Csv -Path c:\users.csv | ForEach-Object {
New-MsolUser -FirstName $_.FirstName -LastName $_.LastName
-UserPrincipleName $_.UserPrincipleName
-DisplayName "$($_FirstName) $($_Lastname)"
_LicenseAssignment 'funkthedogPublishing:ENTERPRISEPACK'
-UsageLocation US
}

# Importing multiple groups

Import-Csv -Path c:\groups.csv | ForEach-Object {
New-Msolgroupr 
-DisplayName $_.DisplayName
-Descriptrion $_.Description
-TenantID $_.TenantID
}