0

I have a situation where I need to test the negative behavior of my product, my product executes power-shell script in 64 bit OS with 64 bit Power-shell and with 32 -bit OS it executes with 32-bit Powershell.

I am trying to cover a negative case where I will execute a PS1 script which is specific for 64 bit OS, and should through some exception on 32 bit OS, but not able to find a command.

I tried "get-localuser" but found it is working with 32 bit OS as well.

Any command which will work only on 64 bit OS but not with 32 bit OS

user2256009
  • 169
  • 1
  • 2
  • 9
  • Might be a duplicate; does this answer your question: https://stackoverflow.com/questions/31977657/determining-32-64-bit-in-powershell – ScriptAutomate Sep 27 '19 at 06:34
  • @ScriptAutomate This is not duplicate of the above question, I already checked it, I dont want to determine the OS architecture, I am already aware it is 32 bit OS, I just need a command which will work only on 64 bit OS, not 32 bit widnows – user2256009 Sep 27 '19 at 06:41
  • 2
    Ah, so is your question more "Are there any cmdlets in PowerShell that are only available on 64-bit OS?" rather than "How can I throw an error if running on a 32-bit OS?" You can throw an error by checking `[Environment]::Is64BitOperatingSystem` and throwing an error if you wanted. I suppose I am trying to better understand what it is you are trying to do or test. – ScriptAutomate Sep 27 '19 at 06:44
  • 1
    I tried this https://stackoverflow.com/questions/58010799/powershell-script-which-cant-run-using-32bit-ps-executor " $PtrSize = [IntPtr]::Size if ($PtrSize -eq 4) { throw "I want 64bit powershell" }" and somehow its fine, but here I am explicitly throwing an exception, but thoght if there would be a better approach where windows command itself through excetion – user2256009 Sep 27 '19 at 06:46
  • 1
    If this is the same question, please close this. Use the other. The comments on your linked question, one where you asked the same thing, answers what you are looking for. You can use `[System.Environment]::Is64BitProcess` to check, and throw an exception. You can use `Write-Error -Message "This script is only meant to be executed in 64-bit PowerShell" -ErrorAction Stop` and like the comments show in that other discussion, $PtrSize might be OS-specific, not process specific. 32-bit PowerShell can still be executed on a 64-bit OS, and it sounds like you do not want that, correct? – ScriptAutomate Sep 27 '19 at 06:56
  • Possible duplicate of [Powershell script which cant run using 32bit PS executor](https://stackoverflow.com/questions/58010799/powershell-script-which-cant-run-using-32bit-ps-executor) – ScriptAutomate Sep 27 '19 at 07:01

0 Answers0