Junedi_miaj
New Member.
2241 views

PowerShell Script Execution with Operations Orchestration

Jump to solution

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

Labels (1)
Tags (2)
0 Likes
1 Solution

Accepted Solutions
Micro Focus Expert
Micro Focus Expert

Re: PowerShell Script Execution with Operations Orchestration

Jump to solution

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

0 Likes
4 Replies
Junedi_miaj
New Member.

Re: PowerShell Script Execution with Operations Orchestration

Jump to solution

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"

 

 

0 Likes
Micro Focus Expert
Micro Focus Expert

Re: PowerShell Script Execution with Operations Orchestration

Jump to solution

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

0 Likes
Junedi_miaj
New Member.

Re: PowerShell Script Execution with Operations Orchestration

Jump to solution

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

0 Likes
Junedi_miaj
New Member.

Re: PowerShell Script Execution with Operations Orchestration

Jump to solution

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

 

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.