Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Powershell API - 64/32bit session
#1
I got my script for creating objects in ASG working in an 32bit powershell, with help for this tread:
http://forum.asg-rd.com/showthread.php?t...1#pid46501

But I really need to integrate my script into another 64bit powershell script. So I thought that I could start a 32bit session from within 64bit powershell and work around it that way.

Heres my code:

Code:
# Creating 32bit session
$machineName = [Environment]::MachineName;  
$session = New-PSSession -ComputerName $machineName -ConfigurationName Microsoft.PowerShell32

# Scriptblock 
$block = {

$workingdir = "C:\Program Files (x86)\ASG-Remote Desktop 2016\"

Set-Location $workingdir
[Environment]::CurrentDirectory = Get-Location -PSProvider FileSystem

$path = $workingdir + "ASGRD-PSAPI.dll"

Add-Type -path $path
[reflection.assembly]::LoadFrom($path) | Import-Module


#Connection to the Environment
Connect-RDEnvironment -Environment "Test" -PassThrough
}

# Running the Scriptblock in the 32bit session
invoke-Command -Session $session -ScriptBlock $block 

It all goes well until the Connect-RDEnvironment, here's the error I get:
WARNING: Environment could not be connected.
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.
At line:13 char:1
+ Connect-RDEnvironment -Environment "Test"  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Smile [Connect-RDEnvironment], InvalidOperationException
    + FullyQualifiedErrorId : System.InvalidOperationException,CloudAdminPSModule.CmdLetEnvironment+RDBaseItemChildsGetCommand

It's the "not running in UserInteractive" part that puzzels me. I tried defining the username and password instead of the -PassThrough option, but still gets the same error.
As I said, when running the script in 32bit powershell, it works and the is no "UserInteractive" like a popup or anything..
Any ideas ?
Reply
#2
There are some 32bit libs that are linked so I guess it is not possible at the moment.

We will publish a 64bit version with the next update - there are some limitations but Powershell can be used in 64bit mode then...
Regards/Gruss
Oliver
Reply
#3
Just to wrap this up - I managed to call a 32 bit PS script form a 64bit one and pass the variables.  :D


Code:
Start-Process -FilePath  "C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe" -argument "C:\Temp\CreateConnection.ps1 -ConnectionfolderID $ConnectionfolderID -CredentialfolderID $CredentialfolderID -vmFqdn $vmFqdn -IP $IP -Password $Password"

This was a pain the the a.. but got it working.
If anyone has the same problem, I'm happy to help...
Reply
#4
(31-05-2017, 02:39 PM)Nice, what is the contents of CreateConnection.PS1? Wrote: Just to wrap this up - I managed to call a 32 bit PS script form a 64bit one and pass the variables.  :D


Code:
Start-Process -FilePath  "C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe" -argument "C:\Temp\CreateConnection.ps1 -ConnectionfolderID $ConnectionfolderID -CredentialfolderID $CredentialfolderID -vmFqdn $vmFqdn -IP $IP -Password $Password"

This was a pain the the a.. but got it working.
If anyone has the same problem, I'm happy to help...
Reply
#5
Sorry, did't see the question there at first...
Code:
param(

   [Parameter(Mandatory=$True)]
   [ValidateNotNullOrEmpty()]
   [string]$ConnectionfolderID,

   [Parameter(Mandatory=$True)]
   [ValidateNotNullOrEmpty()]
   [string]$CredentialfolderID,

   [Parameter(Mandatory=$True)]
   [ValidateNotNullOrEmpty()]
   [string]$vmFqdn,

   [Parameter(Mandatory=$True)]
   [ValidateNotNullOrEmpty()]
   [string]$vmip,

   [Parameter(Mandatory=$True)]
   [ValidateNotNullOrEmpty()]
   [string]$vmadminpassword

   )


$workingdir = "C:\Program Files (x86)\ASG-Remote Desktop 2016\"

Set-Location $workingdir
[Environment]::CurrentDirectory = Get-Location -PSProvider FileSystem

$path = $workingdir + "ASGRD-PSAPI.dll"

Add-Type -path $path
[reflection.assembly]::LoadFrom($path) | Import-Module

#Connection to the Environment
Connect-RDEnvironment -Environment "test" -Username test -Password test -InternalUser

#Create Connection
New-RDBaseItem -ParentItemId $ConnectionfolderID -ItemType Connection -Text $vmFqdn

#Get Connection ID
$ConnectionID = Get-RDBaseItemId -ItemPath "test\$vmFqdn"

#Edit Connection Values
Set-RDPropertiesConnection -ItemId $ConnectionID -Destination $vmip -Protocol RDP -IpAddress $vmip

#Create Credentials
New-RDBaseItem -ParentItemId $CredentialfolderID -ItemType Credential -Text $vmFqdn

#Get Credentials ID
$CredentialsID = Get-RDBaseItemId -ItemPath "test\$vmFqdn"

#Edit Credentials Values
Set-RDPropertiesCredential -ItemId $CredentialsID -Username Administrator -Password $vmadminpassword
Reply




Users browsing this thread: 1 Guest(s)