Execute the script in Orchetrator runbook to change User UPN in Azure

vijayaragavan Hariharan 1 Reputation point
2020-12-03T17:51:33.047+00:00

Hello,

i have a pwershell script that runs and change the UPN name in Azure.
I executed the script manually from Powershell command prompt in Orchestrator server, it work well and changed the UPN in Azure.
Later, i copied the script into Orchestrator. Added Run .Net script activity and pasted the exact same script.
Runbook activity shows success but UPN doesn't changed in Azure.
Is there something i need to add to use the same script in Runbook activities

Below is the script, this works well if i executed the same from powershell prompt in Orch server but no result when i used the same script in Orchestrator activity

$username = "xxxxx@AB .onmicrosoft.com"
$password = Get-Content -Path "C:\pwd.txt" | ConvertTo-SecureString
$credential = New-Object System.Management.Automation.PSCredential($username,$password)
Import-Module AzureAD
Connect-AzureAD -Credential $credential
$user = Get-ADUser xxxxx -Properties c -server xxxx
$old = $user.samaccountname + "@Nicholas .com"
$new = $user.samaccountname + "@gxxx.onmicrosoft.com"
Set-AzureADUser -ObjectID $old -UserPrincipalName $new
Set-AzureADUser -ObjectID $new -UsageLocation $user.c

Regards,
Vijay

System Center Orchestrator
System Center Orchestrator
A family of System Center products that provide an automation platform for orchestrating and integrating both Microsoft and non-Microsoft IT tools.
217 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Leon Laude 85,686 Reputation points
    2020-12-03T18:04:45.523+00:00

    Hi @vijayaragavan Hariharan ,

    The Run .Net Script runbook activity will always return "Success" because it doesn't know/care what actually runs inside, the issue is that the Run .Net Script still runs a 32-bit instance of PowerShell and might still run PowerShell version 2, to run the native PowerShell version you can for example use the Invoke-Command within a Run.Net Script runbook activity and run your entire script within the Invoke-Command.

    For example:

    Invoke-Command -ComputerName localhost -Scriptblock {  
       #Your Code  
    }  
    

    The code inside script block will run in a 64-bit PowerShell and it will also run the native PowerShell version.

    Or you can use one of the methods that I have mentioned here:
    https://thesystemcenterblog.com/wp-content/uploads/2018/05/Making-Orchestrator-to-use-native-powershell-version.pdf

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Best regards,
    Leon

    0 comments No comments