Создание почтового ящика имеющемуся пользователю АД

$User = «resproject\user»
$PWord = ConvertTo-SecureString -String «password» -AsPlainText -Force
$Credential = New-Object -TypeName «System.Management.Automation.PSCredential» -ArgumentList $User, $PWord
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://cas1.resproject.ru/PowerShell/ -Authentication Kerberos -Credential $Credential
Import-PSSession $Session -AllowClobber -ErrorVariable err

$log = «c:\123.log»

$SAMAccountName = «test2»
if ([string]::IsNullOrEmpty($err))
{
Get-User -Identity $SAMAccountName | Enable-Mailbox -Database «MBX_BASE1» -ErrorVariable ExErr
if ([string]::IsNullOrEmpty($ExErr))
{
Out-File -FilePath $log -InputObject (Get-Mailbox -Identity $SAMAccountName) -Encoding utf8 -Append
}
else
{
Out-File -FilePath $log -InputObject («Mailbox for user » + $UserName + «.» + $UserSurname + » was/wasn’t created. Error: «+$ExErr) -Encoding utf8 -Append
}

Remove-PSSession $Session
}
else
{
Out-File -FilePath $log -InputObject («Mailbox for user » + $UserName + «.» + $UserSurname + » was not created. Error: «+$err) -Encoding utf8 -Append
}

Оставьте комментарий

Яндекс.Метрика