ОБНОВЛЕНИЕ
Я успешно подключился к службе администрирования Office 365 и Exchange Online Services. Я протестировал такие командлеты, как Get-MsolUser, и они работают нормально. Однако, когда я пытаюсь запустить команду Set-MsolUser для изменения заголовка, я получаю сообщение об ошибке «Доступ запрещен», как показано ниже. Это странно, потому что я могу вручную go войти в Exchange и изменить любое свойство, которое захочу, но это не позволяет мне выполнить эту команду? В любом случае?
Скрипт для обновления атрибутов пользователя Office 365
## Variables
$systemmessagecolor = "cyan"
$processmessagecolor = "green"
$savedcreds=$false ## false = manually enter creds, True = from file
$credpath = "c:\downloads\tenant.xml" ## local file with credentials if required
## If you have running scripts that don't have a certificate, run this command once to disable that level of security
## set-executionpolicy -executionpolicy bypass -scope currentuser -force
Clear-Host
write-host -foregroundcolor $systemmessagecolor "Script started`n"
#install-module msonline
Import-Module -Name "C:\Temp\MsOnline" -Verbose
write-host -foregroundcolor green "MSOnline module loaded"
## Get tenant login credentials
$cred = Get-Credential
## Connect to Office 365 admin service
connect-msolservice -credential $cred
write-host -foregroundcolor $systemmessagecolor "Now connected to Office 365 Admin service"
## Start Exchange Online session
$EXOSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell -Credential $cred -Authentication Basic -AllowRedirection
import-PSSession $EXOSession -AllowClobber
write-host -foregroundcolor $processmessagecolor "Now connected to Exchange Online services`n"
write-host -foregroundcolor $systemmessagecolor "Script Completed`n"
# Load data from file.csv
$EXUsers = Import-csv file_path.csv
# Count variable for number of users update
$count = 0
# Go through each row that has user data in the CSV we just imported
ForEach($User in $EXUsers)
{
# Ppopulate hash table for Get-Msoluser splatting:
$GetParams =
@{
UserPrincipalName = $User.userPrincipalName
}
# Initialize hash table for Set-Msoluser splatting:
$SetParams =
@{
UserPrincipalName = $User.userPrincipalName
Title = $User.title
}
# Get user and update.
if ( Get-Msoluser @GetParams)
{
# Set User attributes
Set-MsolUser @SetParams
# Print that the user was updated
Write-Host -ForegroundColor Yellow "$User - User attributes have been updated."
# Update Count
$count += 1
}
}
# Print the number of updated users
Write-Host $count "Users have been updated" -ForegroundColor Green
Сообщение об ошибке:
Set-Msoluser : Access Denied. You do not have permissions to call this cmdlet.
At line:1 char:59
+ ... ncipalName "name@company.com" | Set-Msoluser -Title "Test Title"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [Set-MsolUser], MicrosoftOnlineException
+ FullyQualifiedErrorId : Microsoft.Online.Administration.Automation.AccessDeniedException,Microsoft.Online.Administration.Automation.SetUser