Hello
I need to read/store a password in the Adaxes System.
I have created this script:
Import-Module Adaxes
$exchangeServer = "exchangeserver.CH" # TODO: modify me
# Get the name of the domain of the master account
#$linkedDomainName = $Context.GetObjectDomain("%distinguishedName%")
$linkedDomainName = "linked.ch"
# Get domain controlers in the domain of the master account
$linkedDomainControler = "dclinked.linked.ch"
# Get credentials for the resource domain
$exchangeAdminName = $Context.RunAs.UserName
$exchangeAdminPassword = ConvertTo-SecureString -AsPlainText -Force -String $Context.RunAs.Password
$credential = New-Object -TypeName System.Management.Automation.PSCredential($exchangeAdminName, $exchangeAdminPassword)
# Connect to Exchange Server in the resource domain and create linked mailbox
$session = New-PSSession –ConfigurationName Microsoft.Exchange –ConnectionUri "http://$exchangeServer/PowerShell/" -Credential $credential
Import-PSSession $session -AllowClobber -DisableNameChecking
$Context.LogMessage($linkedDomainControler, "Information")
try
{
$linkedReadUser = "linked\adaxesread"
$linkedReadPassword = ConvertTo-SecureString -AsPlainText -Force -String "supersecurepassword."
$credentialExploit = New-Object -TypeName System.Management.Automation.PSCredential($linkedReadUser, $linkedReadPassword)
set-User -Identity '%sAMAccountName%' -LinkedDomainController $linkedDomainControler -LinkedMasterAccount "linked\%username%" -UserPrincipalName "%username%@linked.ch" -LinkedCredential $credentialExploit
}
catch
{
$Context.LogMessage($linkedDomainControler.DNSHostName + ":" + $_.Exception.Message, "Warning")
continue
}
Remove-PSSession $session
The problem is the line
$linkedReadPassword = ConvertTo-SecureString -AsPlainText -Force -String "supersecurepassword."
I prefer that I can store the password secure in Adaxes and read this information for the script.
Like in this line
$exchangeAdminPassword = ConvertTo-SecureString -AsPlainText -Force -String $Context.RunAs.Password
My script do only set the LinkedMasterAccount in the Resource Forest to activate a Linked mailbox in Exchange.
I must run the script unter a user from the Resource Forest who have access to Exchange.
The command set-user need a user/pwd from the Linked Domain as parameter.
Thank you for your help.
Regards
Gustav