使用 Office 365 PowerShell 管理用户帐户和许可证(十二)Configure user account properties with Office 365 PowerShel



Configure user account properties with Office 365 PowerShell

 

上一次修改主题:2017-04-17

Summary: Use Office 365 PowerShell to configure properties of individual or multiple user accounts in your Office 365 tenant.

Although you can use the Office 365 Admin center to configure properties for the user accounts of your Office 365 tenant, you can also use Office 365 PowerShell and do some things that the Office 365 Admin center cannot.

本主题中的步骤需要您连接到 Office 365 PowerShell。有关说明,请参阅连接到 Office 365 PowerShell

To configure properties for a specific user account, you use the Set-MsolUser cmdlet and specify the properties to set or change. This example command changes Belinda Newman's usage location to France:

Set-MsolUser -UserPrincipalName "BelindaN@litwareinc.onmicosoft.com" -UsageLocation "FR"

You identify the account with the -UserPrincipalName parameter and set or change specific properties with additional parameters. Here is a list of the most common parameters.

  • -City "<city name>"

  • -Country "<country name>"

  • -Department "<department name>"

  • -DisplayName "<full user name>"

  • -Fax "<fax number>"

  • -FirstName "<user first name>"

  • -LastName "<user last name>"

  • -MobilePhone "<mobile phone number>"

  • -Office "<office location>"

  • -PhoneNumber "<office phone number>"

  • -PostalCode "<postal code>"

  • -PreferredLanguage "<language>"

  • -State "<state name>"

  • -StreetAddress "<street address>"

  • -Title "<title name>"

  • -UsageLocation "<2-character country or region code>"

    This is the ISO 3166-1 alpha-2 (A2) two-letter country or region code.

See Set-MsolUser for additional parameters.

To see the User Principal Names of all your users, run the following command.

Get-MSolUser | Sort-Object UserPrincipalName | Select-Object UserPrincipalName | More

This command instructs Office 365 PowerShell to:

  • Get all of the information on the user accounts (Get-MsolUser) and send it to the next command ( | ).

  • Sort the list of User Principal Names alphabetically (Sort-Object UserPrincipalName) and send it to the next command ( | ).

  • Display just the User Principal Name property for each account (Select-Object UserPrincipalName).

  • Display them one screen at a time (More).

This command will list all of your accounts. If you want to display the User Principal Name for an account based on its display name (first and last name), fill in the $userName variable below (removing the < and > characters), and then run the following commands:

$userName="<Display name>"
Write-Host (Get-MsolUser | where {$_.DisplayName -eq $userName}).UserPrincipalName

This example displays the User Principal Name for the user named Caleb Sills.

$userName="Caleb Sills"
Write-Host (Get-MsolUser | where {$_.DisplayName -eq $userName}).UserPrincipalName

By using a $upn variable, you can make changes to individual accounts based on their display name. Here is an example of setting Belinda Newman's usage location to France, but specifying her display name rather than her User Principal Name:

$userName="<Display name>"
$upn=(Get-MsolUser | where {$_.DisplayName -eq $userName}).UserPrincipalName
Set-MsolUser -UserPrincipalName $upn -UsageLocation "FR"

To change properties for all users, you can use the combination of the Get-MsolUser and Set-MsolUser cmdlets. The following example changes the usage location for all users to France:

Get-MsolUser | Set-MsolUser -UsageLocation "FR"

This command instructs Office 365 PowerShell to:

  • Get all of the information on the user accounts (Get-MsolUser) and send it to the next command ( | ).

  • Set the user location to France (Set-MsolUser –UsageLocation "FR").

To change properties for a specific set of user account, you can use the combination of the Get-MsolUserWhere-Object, and Set-MsolUser cmdlets. The following example changes the usage location for all the users in the Accounting department to France:

Get-MsolUser | Where-Object {$_.Department -eq "Accounting"} | Set-MsolUser -UsageLocation "FR"

This command instructs Office 365 PowerShell to:

  • Get all of the information on the user accounts (Get-MsolUser) and send it to the next command ( | ).

  • Find all of the user accounts that have their Department property set to "Accounting" (Where-Object {$_.Department –eq "Accounting"}) and send the resulting information to the next command ( | ).

  • Set the user location to France (Set-MsolUser –UsageLocation "FR").

  • Display them one screen at a time (More).

To configure properties for user accounts with the Azure Active Directory V2 PowerShell module, you use the Set-AzureADUsercmdlet and specify the properties to set or change. But first, you must connect to your subscription. For the instructions, see Connect with the Azure Active Directory V2 PowerShell module.

This example command changes Belinda Newman's usage location to France:

Set-AzureADUser -ObjectID "BelindaN@litwareinc.onmicosoft.com" -UsageLocation "FR"

You identify the account with the -ObjectID parameter and set or change specific properties with additional parameters. Here is a list of the most common parameters.

  • -Department "<department name>"

  • -DisplayName "<full user name>"

  • -FacsimilieTelephoneNumber "<fax number>"

  • -GivenName "<user first name>"

  • -Surname "<user last name>"

  • -Mobile "<mobile phone number>"

  • -JobTitle "<job title>"

  • -PreferredLanguage "<language>"

  • -StreetAddress "<street address>"

  • -City "<city name>"

  • -State "<state name>"

  • -PostalCode "<postal code>"

  • -Country "<country name>"

  • -TelephoneNumber "<office phone number>"

  • -UsageLocation "<2-character country or region code>"

    This is the ISO 3166-1 alpha-2 (A2) two-letter country or region code.

See Set-AzureADUser for additional parameters.

To obtain the User Principal Name of a specific user, run the following command.

Get-AzureADUser | Sort-Object UserPrincipalName | Select-Object UserPrincipalName | More

This command instructs Office 365 PowerShell to:

  • Get all of the information on the user accounts (Get-AzureADUser) and send it to the next command ( | ).

  • Sort the list of User Principal Names alphabetically (Sort-Object UserPrincipalName) and send it to the next command ( | ).

  • Display just the User Principal Name property for each account (Select-Object UserPrincipalName).

This command will list all of your accounts. If you want to display the User Principal Name for an account based on its display name (first and last name), fill in the $userName variable below (removing the < and > characters), and then run the following commands:

$userName="<Display name>"
Write-Host (Get-AzureADUser | where {$_.DisplayName -eq $userName}).UserPrincipalName

This example displays the User Principal Name for the user named Caleb Sills.

$userName="Caleb Sills"
Write-Host (Get-AzureADUser | where {$_.DisplayName -eq $userName}).UserPrincipalName

By using a $upn variable, you can make changes to individual accounts based on their display name. Here is an example of setting Belinda Newman's usage location to France, but specifying her display name rather than her User Principal Name:

$userName="<Display name>"
$upn=(Get-AzureADUser | where {$_.DisplayName -eq $userName}).UserPrincipalName
Set-AzureADUser -ObjectID $upn -UsageLocation "FR"

To change properties for all users, you can use the combination of the Get-AzureADUser and Set-AzureADUser cmdlets. The following example changes the usage location for all users to France:

Get-AzureADUser | Set-AzureADUser -UsageLocation "FR"

This command instructs Office 365 PowerShell to:

  • Get all of the information on the user accounts (Get-AzureADUser) and send it to the next command ( | ).

  • Set the user location to France (Set-AzureADUser –UsageLocation "FR").

To change properties for a specific set of user account, you can use the combination of the Get-AzureADUserWhere-Object, andSet-AzureADUser cmdlets. The following example changes the usage location for all the users in the Accounting department to France:

Get-AzureADUser | Where-Object {$_.Department -eq "Accounting"} | Set-AzureADUser -UsageLocation "FR"

This command instructs Office 365 PowerShell to:

  • Get all of the information on the user accounts (Get-AzureADUser) and send it to the next command ( | ).

  • Find all of the user accounts that have their Department property set to "Accounting" (Where-Object {$_.Department –eq "Accounting"}) and send the resulting information to the next command ( | ).

  • Set the user location to France (Set-AzureADUser –UsageLocation "FR").

1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 、4下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合;、下载 4使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合;、 4下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值