Mostrar mensagens com a etiqueta Office 365. Mostrar todas as mensagens
Mostrar mensagens com a etiqueta Office 365. Mostrar todas as mensagens

quarta-feira, 28 de outubro de 2015

Some Useful Office 365 PowerShell commands

 

1. Set Password never expired

Set Password never expired for Office 365 user

PowerShell command Syntax

  • PowerShell

    Set-msoluser –UserPrincipalName <UserPrincipalName> -PasswordNeverExpires $True


PowerShell command Example

  • PowerShell

    Set-MsolUser –UserPrincipalName John@o365info.com -PasswordNeverExpires $True
    Disable Password never expired option for a Office 365 user

PowerShell command Syntax

  • PowerShell

    Set-MsolUser –UserPrincipalName <UserPrincipalName>  -PasswordNeverExpires $False


PowerShell command Example

  • PowerShell

    Set-MsolUser -UserPrincipalName John@o365info.com -PasswordNeverExpires $False
    Set Password never expired for ALL Office 365 users (Bulk Mode)

PowerShell command Syntax

  • PowerShell

    Get-MsolUser | Set-MsolUser –PasswordNeverExpires $True
    Re-enable Password expired ( the default) for ALL Office 365 users (Bulk Mode)

PowerShell command Syntax

  • PowerShell

    Get-MsolUser | Set-MsolUser –PasswordNeverExpires $False

2. Set Password

Set a Predefined Password for Office 365 user

PowerShell command Syntax

  • PowerShell

    Set-MsolUserPassword –UserPrincipalName <UserPrincipalName> –NewPassword <New Password> -ForceChangePassword $False


PowerShell command Example

  • PowerShell

    Set-MsolUserPassword -UserPrincipalName John@o365info.com -NewPassword ww#322x -ForceChangePassword $False
    Set a Predefined Password for all Office 365 users (Bulk mode)

PowerShell command Syntax

  • PowerShell

    Get-MsolUser |%{Set-MsolUserPassword -userPrincipalName $_.UserPrincipalName –NewPassword <password> -ForceChangePassword $False}

PowerShell command Example

  • PowerShell

    Get-MsolUser |%{Set-MsolUserPassword -userPrincipalName $_.UserPrincipalName –NewPassword Abc#45 -ForceChangePassword $False}
    Set a Predefined Password for Office 365 users imported from a CSV File

Step 1: Export Office 365 users account


PowerShell command Syntax

  • PowerShell

    Get-MsolUser | Select UserPrincipalName| Export-CSV
    Step 2:

Set a Predefined Password

  • PowerShell

    Import-CSV  |%{Set-MsolUserPassword -userPrincipalName $_.UserPrincipalName –NewPassword <Password>  -ForceChangePassword $False}
    Example: Step 1: Export Office 365 users account

Predefined Password-CSV

PowerShell command Example

  • PowerShell

    Get-MsolUser | Select UserPrincipalName|Export-CSV C:\Temp\o365users.csv
    PowerShell

    Import-CSV C:\Temp\o365users.csv |%{Set-MsolUserPassword -userPrincipalName $_.UserPrincipalName –NewPassword AbcAs123 -ForceChangePassword $False}


Create new Office 365 user and set a unique temporary password by import the information from CSV file

temp password

You can download a sample CSV file – Password.csv
PowerShell command Example

  • PowerShell

    Import-CSV –Path C:\Temp\users.csv| ForEach-Object { New-MsolUser -UserPrincipalName $_.UserPrincipalName -FirstName $_.FirstName -LastName $_.LastName  -DisplayName "$($_.FirstName) $($_.LastName)" –Password $_.Password –UsageLocation “US” }

Provisioning Office 365 user and export information from Active Directory

In case that you need to export Active Directory on-Premise user account based on a specific parameter, you can use the PowerShell cmdlets named – get-aduser (you will need to use PowerShell console from DC or import the Active Directory cmdlets to the existing PowerShell console


For example:

Example 1 – display or export, all of the Active Directory users that are located in a specific OU.

In our specific scenario, the domain name is – o365info.com and the specific OU is – Test

Display information about – all of the Active Directory users that are located in a specific OU

PowerShell command Example

  • PowerShell

    Get-ADUser -LDAPfilter '(name=*)' -searchBase {OU=test,DC=o365info,dc=local}

Export to a CSV file information about – all of the Active Directory users that are located in a specific OU + choose a specific data fields.

  • PowerShell

    $usersfromOU = Get-ADUser -LDAPfilter '(name=*)' -searchBase {OU=test,DC=o365info,dc=local}
    $usersfromOU | export-csv C:\usersbyOU.csv
    Example 2 – display + export information about Active Directory users from a specific department.

The PowerShell command syntax is:

  • PowerShell

    $Users = Get-AdUser -filter "department -eq '<name>'"

An example to a scenario in which we want to export information only about Active Directory users that belong to the marketing department could be

  • PowerShell

    $aduserdep = Get-AdUser -filter "department -eq 'marketing'" -Properties City,Title,Department,GivenName,Surname
  • PowerShell

    $aduserdep | export-csv c:\aduserdep.csv
    Set a Temporary Password for a specific user

PowerShell command Syntax

  • PowerShell

    Set-MsolUserPassword –UserPrincipalName  <UserPrincipalName> –NewPassword <New Password>-ForceChangePassword $True

PowerShell command Example

  • PowerShell

    Set-MsolUserPassword -UserPrincipalName John@o365info.com -NewPassword ww@322x -ForceChangePassword $True

Set a Temporary Password for all Office 365 users (Bulk Mode)

PowerShell command Syntax

  • PowerShell

    Get-MsolUser | Set-MsolUserPassword –NewPassword <New Password> -ForceChangePassword $False

PowerShell command Example

  • PowerShell

    Get-MsolUser | Set-MsolUserPassword -NewPassword ww#322x -ForceChangePassword $False

3. Office 365 Password Policy

PowerShell command Syntax

  • PowerShell
    Set-MsolPasswordPolicy -DomainName  <Domain Name> -NotificationDays <Number Of Days> –ValidityPeriod <Number Of Days>

PowerShell command Example

  • PowerShell

    Set-MsolPasswordPolicy -DomainName o365info.com -NotificationDays 15 -ValidityPeriod 180

4. Display Password settings

Display Password settings for all Office 365 users

PowerShell command Syntax

  • PowerShell

    Get-MsolUser | Select UserPrincipalName,PasswordNeverExpires

Display information about Office 365 Password Policy

PowerShell command Syntax

  • PowerShell

    Get-MsolPasswordPolicy –DomainName <Domain Name>

PowerShell command Example

  • PowerShell

    Get-MsolPasswordPolicy –DomainName  o365info.com

Connect to Office 365 Cloud Services using PowerShell

You can use the following versions of Windows:
  • Windows 8 or Windows 8.1
  • Windows Server 2012 or Windows Server 2012 R2
  • Windows 7 Service Pack 1 (SP1)*
  • Windows Server 2008 R2 SP1*
* You need to install the Microsoft .NET Framework 4.5 or 4.5.1 and then either the Windows Management Framework 3.0 or the Windows Management Framework 4.0. For more information, see Installing the .NET Framework 4.5, 4.5.1 and Windows Management Framework 3.0 or Windows Management Framework 4.0.

You need to install the modules that are required for Office 365, SharePoint Online, and Skype for Business Online:

  • Microsoft Online Service Sign-in Assistant for IT Professionals RTW
  • Windows Azure Active Directory Module for Windows PowerShell (64-bit version)
  • SharePoint Online Management Shell
  • Windows PowerShell Module for Lync Online (Skype for Business Online)


Connect to Exchange Online

On your local computer, open Windows PowerShell and run the following command.

  • $UserCredential = Get-Credential

In the Windows PowerShell Credential Request dialog box, type your Exchange Online user name and password, and then click OK.


  • Run the following command.


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


Run the following command.



  • Import-PSSession $Session


If you get and error like "Import-PSSession : Files cannot be loaded because running scripts is disabled on this system. P", run this: 



  • Set-ExecutionPolicy Unrestricted
and then again: 

  • Import-PSSession $Session
When done: Remove-PSSession $Session to clear the session