Start code in 32bit and 64bit powershell at the same time(one session)

Welcome Forums General PowerShell Q&A Start code in 32bit and 64bit powershell at the same time(one session)

Viewing 4 reply threads
  • Author
    Posts
    • #248674
      Participant
      Topics: 3
      Replies: 5
      Points: 48
      Rank: Member

      Hi,

      I’m opening a power-shell session(64bit) to a remote computer. In that session a lot of scripts(functions) are getting executed. I am trying to connect to an Oracle db server and execute some queries there. Before actual connection, there are couple of tests that are getting executed, pre-deployment tests, where we are checking if connection to the database is good, sftp connection is ok, ssh connection, they are executed one by one. If all that tests are passing, then we start deployment.

      Before starting the tests we are loading all the power-shell scripts where those functions are (for db connection test, ssh connection..). Like this :

      After they are loaded, tests are starting to execute. We have a separate power-shell script for each test.
      First test is connection to the database. There is a script called Db_Connection_test.ps1 which has the following code:

      $TestResult = TestDBConnection $RunSettings.ConnectionString

      All the needed functions for db connection live in DatabaseActions.ps1 script(including TestDBConnection) :

      [/crayon] [/crayon] [/crayon]

      The problem here is that I need to execute the first test in power-shell 32bit because of the Oracle-Client dll. It throws an error in 64bit. But it is one session, so I need to execute that test in 32bit and again continue in 64bit because of the other tests. I tried to start everything in 32bit session, connection to the database is good, but the other tests like ssh connection is falling because the ssh client is 64bit.

      I tried this approach by defining an alias when starting the session like this :

      Set-Alias Start-PowerShell32 “$env:windir\syswow64\WindowsPowerShell\v1.0\powershell.exe”

      And wrap the code in DatabaseActions.ps1 sript like this:

      [/crayon] [/crayon] [/crayon]

      }
      But then the TestDatabaseConnection is not known, because it is a new session.

      It’s a bit confusing but I tried to explain as much as possible. I hope you can understand what is going on and what is the problem. I really don’t know how to fix this problem. Probably there is a solution but I don’t know it :).

      Would like to hear your suggestions how to fix this.

      Thanks

    • #248926
      Participant
      Topics: 7
      Replies: 557
      Points: 2,122
      Helping Hand
      Rank: Community Hero

      Here is one way you can run a 32bit process from a 64bit console.

      Let’s first capture the 32 bit powershell.exe path as a string
      $32bitpowershell = 'C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe'

      Next we define a scriptblock that will write if it’s in a 32 or 64 bit process.

      [/crayon]

      Now we call it in our current 64 bit console, then execute 32 bit, then 64 one more time for fun.

      [/crayon]

      The output

      [/crayon]
    • #249110
      Participant
      Topics: 3
      Replies: 5
      Points: 48
      Rank: Member

      Thanks, simple and useful explanation.

      I still need to figure out how to implement it in my case.

    • #251522
      Participant
      Topics: 3
      Replies: 5
      Points: 48
      Rank: Member

      Hi Doug,

      When I start for example a 64bit session and in the middle of executing some scripts I need to switch and start 32bit session(like I must do for the 32bit Oracle dll), is there a way I can transfer all the previously loaded scripts from the 64bit session into the 32bit session. Can I transfer some variables from one process to another since it as a new session and it doesn’t know the scripts all the variables from the previous one.

      Thanks

    • #251597
      Participant
      Topics: 7
      Replies: 557
      Points: 2,122
      Helping Hand
      Rank: Community Hero

      If you call with . instead of & then any variable defined in the child scope will remain in the parent scope.

      You could also export the information to a file or database and then read it in with the other script.

      Additionally, you could pass in arguments. Maybe this small example will spark some ideas.

      "" & $32bitpowershell $current } } . $scriptblock "We","are","arguments" [/crayon]
Viewing 4 reply threads
  • You must be logged in to reply to this topic.