Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Running powershell within automation.
#1
Question 
I use an automation tool to deploy servers, this uses NSH scripting which I call powershell scripts from, where required.


I am trying to get the automation to add an RDP connection in to ASG RD 2018.
I have ASGRD 2018 x86 installed and the environment set up, on the server where the powershell script runs, to add the entry in to ASG RD.

The NSH script calls powershell x86 and the .ps1 script, passing the name of the server to it:
Code:
nexec ${host} cmd /c "C:/Windows/SysWOW64/WindowsPowerShell/v1.0/powershell.exe -inputformat none -ExecutionPolicy Bypass C:/tmp/AddServerToVisionApp.ps1 -server_name $SERVER"  

The PowerShell script works fine if I run it locally on the server:
Code:
#0.5 - Testing

param(
[STRING]$Server_Name
)

#establish connection to the correct API dll to import modules
$workingdir = "C:\Program Files (x86)\ASG-Remote Desktop 2018\"
Set-Location $workingdir
[Environment]::CurrentDirectory = Get-Location -PSProvider FileSystem
$path = $workingdir + "ASGRD-PSAPI.dll"
Add-Type -path $path
[reflection.assembly]::LoadFrom($path) | Import-Module

#pass the hostname of the server to $servername
$servername = $Server_Name

#connect to the ASGRD environment
Connect-RDEnvironment -Environment [DELETED SENSITIVE INFO]

# create new connection, the perentitemid can be the root or the id of a subfolder
New-RDBaseItem -ParentItemId 3938b5a5-d1fb-4905-b60b-7fc89184be9c -ItemType Connection -Text $servername

#create path to the item created – must be the full path to the item
$serverpath = Join-Path -path "Connections\IAAS\" -ChildPath $servername

#get the id of the connection created
$serverid = Get-RDBaseItemId -ItemPath $serverpath

#set the destination (address it connects to) to the same as the hostname
Set-RDPropertiesConnection -ItemId $serverid -Destination $servername


However, in our automation tool, when the connection to the environment is attempted, I am getting the following errors:

WARNING: Environment is not connected. Command could not be executed.Connect-RDEnvironment : Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.



Any suggestions?
Reply
#2
I never tried in that way - sorry - the script looks good - but I do not what is different when Powershell is called by another process...
Regards/Gruss
Oliver
Reply
#3
I'm guessing it's something to do with messages being displayed, that can't due to it being 'userless'
Reply
#4
No - if you powershell no UI is displayed - output stream is used for any warnings / errors or other messages
Regards/Gruss
Oliver
Reply
#5
Seems powershell module is loading any other dll or module which is creating a dialog, but not displaying it. 


We will try to solve it by psexec to the server where ASG is installed starting x86 Powershell with our script
Reply
#6
The script looks not bad, but I still cannot understand how it works till the end. I am not an automation professional, and I might now know things well, but this one looks weird to me.

Our company decided to cooperate with https://www.zaptest.com/ui-testing-automation only some months ago. We still have not learned to work with an automated production line. It is good cooperation because now we can make much more productive, but it’s also a little stressful for the workers. But I think that sooner or later, we will learn more and encounter no problems using automated systems sooner or later.
Reply
#7
Just a comment or any question?!?
Regards/Gruss
Oliver
Reply




Users browsing this thread: 1 Guest(s)