#requires

Welcome Forums General PowerShell Q&A #requires

Viewing 3 reply threads
  • Author
    Posts
    • #42141
      Participant
      Topics: 16
      Replies: 50
      Points: 58
      Rank: Member

      I looked in the help about_requires I don't see anything about requiring that the console be launched in 64bit mode. is there a hidden requires statement perhaps? or is there a module that is only loaded in 64 bit powershell but not 32 bit that is common across all or several the versions? On this site (http://www.nivot.org/blog/post/2012/12/18/Ensuring-a-PowerShell-script-will-always-run-in-a-64-bit-shell) I found this snippet (below) is there something easier?

      if ($pshome -like "*syswow64*") {
          write-warning "Restarting script under 64 bit powershell"
       
          # relaunch this script under 64 bit shell
          # if you want powershell 2.0, add -version 2 *before* -file parameter
          & (join-path ($pshome -replace "syswow64", "sysnative") powershell.exe) -file `
              (join-path $psscriptroot $myinvocation.mycommand) @args
       
          # exit 32 bit script
          exit
      }
      
    • #42226
      Participant
      Topics: 0
      Replies: 669
      Points: 0
      Rank: Member

      As far as I'm aware there isn't a requires setting for 32/64 bit

      Most modules run OK in both. I know that some parts of the VMware module only work in 32 bit

      You can also test if running 32/64 bit like this

      if ([System.IntPtr]::Size -eq 8) {$size = '64 bit'}
      else {$size = '32 bit'}

    • #42293
      Participant
      Topics: 16
      Replies: 50
      Points: 58
      Rank: Member

      The reason for the post was I ran into using this class from Dotnet and it couldn't be loaded when using the 32bit shell:

      $mgr = new-object Microsoft.Web.Administration.ServerManager

      After searching further found out that the script that was being called was initially being run in the 32bit shell. So wondered if there was some way I could make sure that the user only used 64 bit version of the shell. That is what prompted this post.

      Since this class is limited to instances of IIS I was looking for something that might have been in any 64 bit version of windows only..

    • #42296
      Participant
      Topics: 3
      Replies: 6
      Points: 1
      Rank: Member

      [Environment]::Is64BitProcess

      • #42303
        Participant
        Topics: 16
        Replies: 50
        Points: 58
        Rank: Member

        nice... thanx Don

Viewing 3 reply threads
  • The topic ‘#requires’ is closed to new replies.