locked
Run powershell .net script RRS feed

  • Question

  • I'm running into issues running powershell scripts with a remote session to exchange 2013 emc.

    I keep getting the following error...

    Cannot process argument transformation on parameter 'Credential'. Cannot invoke this function because the current host does not implement it.

    that's when I run it normally, if I add $mailenableuser = powershell {  } around it it does nothing...

    heres the script.

    Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
    $Session2 = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://EXCHANGESERVER.TEST.com/PowerShell/ -Authentication kerberos -Credential $cred
    $username = "scorch_o365@TEST.com"
    $password = ConvertTo-SecureString -string "PASSWORD" -asplaintext -force
    $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
    Import-PSSession $Session2 -AllowClobber
    $upn = "aboston@TEST.com"
    $email = $upn
    $split = $email.split("@")
    $targetaddress = "smtp:" + $split[0] + "@TEST.mail.onmicrosoft.com"
    $mailnickname = $split[0]
    enable-mailuser -Identity $upn -ExternalEmailAddress $targetaddress > $null
    set-mailuser -Identity $upn -WindowsEmailAddress $email -alias $mailnickname -EmailAddressPolicyEnabled $false > $null
    $proxy = "smtp:" + $mailnickname + "@TEST.onmicrosoft.com"
    set-mailuser -Identity $upn -EmailAddresses @{add= $proxy} > $null
    Get-PSSession
    Exit-PSSession

    If I run it in a powershell window by itself it works perfectly. but in the activity Run .Net Script in Scorch it doesn't work...

    Wednesday, November 25, 2015 8:10 PM

Answers

  • Hello There,

    This issue is with the powershell version usage. When you run manually the script it uses the latest version of powershell and may not when run through ORCH. You can always use the below registry changes to force orch to use the latest one. 

    http://www.sc-orchestrator.eu/index.php/scoblog/128-run-the-powershell-version-of-windows-executing-the-orchestrator-runbook-service-in-run-net-script-activity

    More details in the below link.

    http://stackoverflow.com/questions/2094694/how-can-i-run-powershell-with-the-net-4-runtime


    Priyabrata

    Tuesday, December 1, 2015 2:38 AM

All replies

  • Which PowerShell version do you use on the Runbook Server?

    You can find it out by running PowerShell and then enter $host.version.

    Natascia

    Thursday, November 26, 2015 10:47 AM
  • Major  Minor  Build  Revision
    -----  -----  -----  --------
    4      0      -1     -1
    Monday, November 30, 2015 1:31 PM
  • Hello There,

    This issue is with the powershell version usage. When you run manually the script it uses the latest version of powershell and may not when run through ORCH. You can always use the below registry changes to force orch to use the latest one. 

    http://www.sc-orchestrator.eu/index.php/scoblog/128-run-the-powershell-version-of-windows-executing-the-orchestrator-runbook-service-in-run-net-script-activity

    More details in the below link.

    http://stackoverflow.com/questions/2094694/how-can-i-run-powershell-with-the-net-4-runtime


    Priyabrata

    Tuesday, December 1, 2015 2:38 AM
  • Hi,

    yes, that is the only way, how you can use the commands from a higher PowerShell version. Only keep in mind, that you can loose Microsoft support by changing the registry key.

    Natascia

    Tuesday, December 1, 2015 7:20 AM
  • Are you sure about this?? I havent heard from MS on this anytime sooner... 

    Moderators, can you please throw some light on this pls. 


    Priyabrata


    Tuesday, December 1, 2015 7:37 AM
  • Would be great to get an official statement about this.

    Natascia

    Tuesday, December 1, 2015 7:44 AM