This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

PowerShell script is supposed to fetch the $samAccountName of the modified object and run Enable-mailbox –Identity (Identity = $samAccountname of modified object)

User logon to Active Roles Server Console and modify attribute, the modification will trigger below workflow, then workflow will execute the PowerShell script.

The challenge we have is passing the modified object’s/User’s samAccountname attribute to the PowerShell script on the workflow.

 

 

The PowerShell script is supposed to fetch the $samAccountName of the modified object and run Enable-mailbox –Identity (Identity = $samAccountname of modified object)

 

$samAccountName = "";

$DN = "";

$Request.whoami([ref]$SamAccountName,[ref]$DN)

$Username = 'turtle\lab_admin'

$Password = 'Password@123'

$pass = ConvertTo-SecureString -AsPlainText $Password -Force

$SecureString = $pass

$MySecureCreds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Username,$SecureString

$session = New-PSSession -Configurationname Microsoft.Exchange –ConnectionUri exchange.turtle.Local/PowerShell -Credential $MySecureCreds

#Invoke-Command -Session $session -ScriptBlock {Enable-Mailbox -Identity $args[0] -Database 'Mailbox Database 0004333030'} -ArgumentList $samAcccountName

Import-PsSession $session

Enable-Mailbox -Identity $samAcountName -Database ‘Mailbox Database 0004333030’

 

 

Note:

When we replace the $samAccountName with domain\username in the script and modify the attribute of the same user specified in the PowerShell the results are successful.

 

$Username = 'turtle\lab_admin'

$Password = 'Password@123'

$pass = ConvertTo-SecureString -AsPlainText $Password -Force

$SecureString = $pass

$MySecureCreds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Username,$SecureString

$session = New-PSSession -Configurationname Microsoft.Exchange –ConnectionUri exchange.turtle.Local/PowerShell -Credential $MySecureCreds

#Invoke-Command -Session $session -ScriptBlock {Enable-Mailbox -Identity $args[0] -Database 'Mailbox Database 0004333030'} -ArgumentList $samAcccountName

Import-PsSession $session

Enable-Mailbox -Identity domain\username -Database ‘Mailbox Database 0004333030’

Parents Reply Children
No Data