PowerShell Script Execution with Operations Orchestration

Hi,

One issue with HPE OO, PowerShell Script is running fine when run with Windows PowerShell and adding the local user -- but when ran the same script within HPE OO it is executing successfully but not adding local user in the system.

Any idea or faced similar issue?

 

Regards,

Junedi

  • This is the script sample used to add the local user:--

    [CmdletBinding()]
    Param(
    [string[]]$ComputerName = $env:COMPUTERNAME,

    [Parameter(Mandatory=$true)]
    [ValidateSet("Group","User")]
    [string]$ObjectType,

    [Parameter(Mandatory=$true)]
    [string]$ObjectName,

    [Parameter(Mandatory=$true)]
    [string]$ObjectPassword

    )

    #if($ObjectType -eq "User") {
    # $PasswordForUser = Read-Host -Prompt "Enter a password for user account" -AsSecureString
    # $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($PasswordForUser)
    # $PlainPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
    #}
    #
    echo $ObjectName
    foreach($Computer in $ComputerName) {
    Write-Host "Working on $Computer"
    if(Test-Connection -ComputerName $Computer -count 1 -Quiet) {
    try {
    $CompObject = [ADSI]"WinNT://$Computer"
    $NewObj = $CompObject.Create("$ObjectType",$ObjectName)
    if($ObjectType -eq "User") {
    $NewObj.SetPassword($ObjectPassword)
    }
    $NewObj.SetInfo()

    Write-Host "$ObjectTYpe with the name $ObjectName created successfully" -ForegroundColor Green
    } catch {
    Write-Warning "Error occurred while creating the group"
    Write-Verbose "More details : $_"

    }
    } else {
    Write-Warning "$Computer is not online"
    }

    }

    ----

    Then  executed with the powershell, It works fine and adds the user--

    PS C:\> .\localusers.ps1 -ObjectType User -ObjectName AppUser1 -ObjectPassword Welcome@123

     

    But when run in HPE OO Powershell Script operation it runs but does not add the user --

    "C:\localusers.ps1 -ObjectType User -ObjectName AppUser1 -ObjectPassword 12"

     

     

  • Verified Answer

    Hi,

    If the script works correctly in powershell, but not in OO try to run studio /central expressly as administrator (open studio with run as administrator option or for central run the service under a domain administrator account). 

    Make sure that powershell remoting is properly set up on both OO and target servers. Try to run the script itself from the powershell script operation instead of remote command execution  to a file on the remote server, in order to see if running the script from OO throws any error in OO. Running the script as a file  shows succsess as the command worked, but will not give you more information about why it failed if it failed. 

    Keep in mind, though that powershell has some commands which it doesn't allow to be run from a remote host. Running this commands from the powershell window opened in a remote desktop connection is ok (you are for all intents and purposes logged in on the server directly), however running them through remote powershell sessions is not ok. This cannot be bypassed even with triggering a script file remotely on the server.

     

    Regards,

    Vlad

  • Thanks VLAD for responding.

    I tried the options provided by you but it did not worked.

    Still the same thing workflow gets completed but the user is not added

  • This is resolved now.

    I have removed a line from the script which was causing the issue and removing the quotes from the HPE OO Script.

    Code from the powershell script for local user removed is -

    Write-Host "Working on $Computer"

    Quotes removed from the HPE OO Operation input Script -

    C:\localusers.ps1 -ObjectType User -ObjectName AppUser1 -ObjectPassword Welcome@123