108
$get_adcomp_props = @{
SearchBase = 'OU=EXMAILDAG,OU=Exchange,OU=Servers,OU=HQ (Shabolovka
31A),' +
'OU=Leroy Merlin
Vostok,DC=hq,DC=ru,DC=corp,DC=leroymerlin,DC=com'
Filter = 'name -notlike "*dag"'
}
$exchange_servers = Get-ADComputer @get_adcomp_props
$exchange_server = Get-Random -InputObject $exchange_servers
$exchange_uri = "http://$($exchange_server.DNSHostName)/PowerShell"
$configuration_name = 'Microsoft.Exchange'
$connection_name = $exchange_server
$pssession_props = @{
ConnectionUri = $exchange_uri;
ErrorAction = 'SilentlyContinue';
}
$existing_session = Get-PSSession @pssession_props
if (-not $existing_session) {
$pssession_props = @{
ConfigurationName = $configuration_name;
ConnectionUri = $exchange_uri;
Name = $connection_name;
}
$session = New-PSSession @pssession_props
$pssession_props = @{
Session = $session;
WarningAction = 'SilentlyContinue';
ErrorAction = 'SilentlyContinue';
}
Import-PSSession @pssession_props | Out-Null
}
$dc = (Get-ADForest).SchemaMaster
$access_group_ou = 'OU=Shared Mailboxes,OU=Exchange,OU=\#Services,' +
'OU=Leroy Merlin Vostok,DC=hq,DC=ru,DC=corp,DC=leroymerlin,DC=com'
$mb_ou = 'OU=Shared Mailboxes,OU=Exchange,OU=\#Services,' +
'OU=Leroy Merlin Vostok,DC=hq,DC=ru,DC=corp,DC=leroymerlin,DC=com'
$description = "$mb_name@ - Full access"
if ($send_as) {
$description += " + Send As"
}
$description += " / $mb_description / ответственный: $responsible"
$access_group_name = "LM-EX-Mailbox-$mb_name-Full"
try {
$get_adgroup_props = @{
Identity = $access_group_name;