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

Sem comentários: