Post

Exchange Remote Management with Powershell

#Define credentials and connection details
$adminUsername = "faruk" # Replace with your admin username
$adminPassword = "123passwd+" # Replace with your admin password
$exchangeUri = "http://exc1.guler/Powershell/" # Exchange PowerShell endpoint

#Create a PSCredential object
$UserCredential = New-Object System.Management.Automation.PSCredential($adminUsername, (ConvertTo-SecureString $adminPassword -AsPlainText -Force))

#Establish a remote PowerShell session to Exchange
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $exchangeUri -Authentication Kerberos -Credential $UserCredential

#Import the session into the current PowerShell session
Import-PSSession $Session -DisableNameChecking -AllowClobber

#Define mailbox details
$password = ConvertTo-SecureString "passwd$$" -AsPlainText -Force # Replace with the desired password
$userPrincipalName = "[email protected]" # the user's email address
$alias = "test_user12" # Replace with the desired alias
$database = "Mailbox_DB1" # Replace with the mailbox database name
$displayName = "Test 12" # Replace with the display name
$ou = "OU=Test_BN,DC=guler,DC=com" # Replace with the organizational unit path
$firstName = "Ahmet" # Replace with the user's first name
$lastName = "Mehmet" # Replace with the user's last name

#Create a new mailbox
New-Mailbox -UserPrincipalName $userPrincipalName -Alias $alias -Database $database -Name $displayName -OrganizationalUnit $ou -Password $password -FirstName $firstName -LastName $lastName

##Any other operations
# create
# delete
# other exc ops.

#Remove the remote session
Remove-PSSession $Session

This post is licensed under CC BY 4.0 by the author.