Author Posts

May 26, 2017 at 6:20 pm

Hello,

I'm trying to output a variable so i can use it in an Orchestrator runbook i am building. Unfortunatly Powershell and Orchestrator don't play nice and some the work arounds I have found don't work. What does work is wrapping all my code in powershell{ }
However this has caused me a problem in getting my output as a variable in one particular script. If i run it without the global variable and replace the write-host with local variables it works fine (in actual powershell not orchestrator. But when i run it with the global variable i get multiple results with = signs and spaces.

$skypemessage=powershell {
Import-Module "skypeforbusiness"
$User = get-csaduser "user"
$status = $User.enabled
If ($status){
Disable-CsUser -Identity "user"
Write-host "User has been disabled from Skype"
} 
Else {
Write-host = "User did not have a Skype account"
}
}

I only want it to return either of the write hosts.

May 30, 2017 at 6:39 pm

I'm not sure about using PowerShell with Orchestrator. However, if you are attempting to limit the content of

$skypemessage

I would try the following changes:

$skypemessage = powershell {

    Import-Module "skypeforbusiness"
    $User = Get-CsAdUser -Identity "user"

    If ($user.Enabled) {

        # Disable-CsUser returns Microsoft.Rtc.Management.ADConnect.Schema.CSADUser object so assigning it to a variable to make 
        # sure its output doesn't make it into $skypemessage
        $disable = Disable-CsUser -Identity "user"
        
        # Write-Host is for writing to the console. I would use Write-Output
        Write-Output "User has been disabled from Skype"
    } 
    Else {
        
        # Again, I believe Write-Output to be the correct choice.
        Write-Output = "User did not have a Skype account"
    }
}

I believe that with this, the content of $skypemessage will be limited to either "User has been disabled from Skype" or "User did not have a Skype account".

May 30, 2017 at 6:52 pm

So, Write-Host output isn't capture-able, really; I'd expect Write-Output to work better (which is what you get when you just "run" the variable on a line by itself). Orchestrator is kind of a craps-shoot with output, in my experience. You might need to do some research into how Orchestrator handles scope, and make sure you're really clear on how PowerShell scope operators, and why it's a bad idea to pretty much ever use Write-Host.

May 31, 2017 at 2:35 pm

Thanks for the replies guys. I was able to get it working by removing the write all together. I'm a newbie with both powershell and orchestrator 🙂

$skypemessage=powershell {
Import-Module "SkypeForBusiness"
$Yes = "User has been disabled from Skype"
$No = "User did not have a Skype account"
$User = get-csaduser "TESTUSER"
$status = $User.enabled
If ($status){
Disable-CsUser -Identity "TESTUSER"
$Yes
} 
Else {
$No
}
}