Powershell: bulk parametr set

88 Views Asked by At

am trying to bulk edit "UsageLocation" for a list of users. Running against one UPN is working fine, but bulk not :-/

CSV example

UPN
[email protected]
[email protected]
[email protected]

Import users from CSV

$userlist = Import-Csv .\users.csv

Set usagelocation before adding a license

Set-MsolUser -UserPrincipalName "[email protected]" -UsageLocation "XY"

Set UsageLocation for users from CSV

$userlist.foreach(
    {
        Set-MsolUser -UserPrincipalName $_.UPN -UsageLocation "XY"
    }
)

Error returned

Set-MsolUser : User Not Found.  User: .
At line:3 char:9
+         Set-MsolUser -UserPrincipalName $_.UPN -UsageLocation "XY"
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [Set-MsolUser], MicrosoftOnlineException
    + FullyQualifiedErrorId : Microsoft.Online.Administration.Automation.UserNotFoundException,Microsoft.Online.Administration.Automation.SetUser

Set-MsolUser : Invalid value for parameter.  Parameter Name: UsageLocation.
At line:3 char:9
+         Set-MsolUser -UserPrincipalName $_.UPN -UsageLocation "XY"
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [Set-MsolUser], MicrosoftOnlineException
    + FullyQualifiedErrorId : Microsoft.Online.Administration.Automation.PropertyValidationException,Microsoft.Online.Administration.Automation.SetUser

Any ideas, please? :-( Thanks a lot.

0

There are 0 best solutions below