确定当前的 PowerShell 进程是 32 位还是 64 位? [英] Determine if current PowerShell Process is 32-bit or 64-bit?
问题描述
在 x64 位操作系统平台上运行 PowerShell 脚本时,如何确定在脚本中该脚本在哪个版本的 PowerShell(32 位或 64 位)上运行?
When running a PowerShell script on a x64-bit OS platform, how can you determine in the script what version of PowerShell (32-bit or 64-bit) the script is running on?
背景
默认情况下,32 位和 64 位版本的 PowerShell 都安装在 64 位平台(例如 Windows Server 2008)上.这可能会导致在运行 PowerShell 脚本时必须针对特定体系结构(即使用 64 位用于 SharePoint 2010 的脚本,以便使用 64 位库).
Background
Both 32-bit and 64-bit versions of PowerShell are installed by default on a 64-bit platform such as Windows Server 2008. This can lead to difficulties when a PowerShell script is ran that must target a specific architecture (i.e. using 64-bit for a script for SharePoint 2010, in order to consume the 64-bit libraries).
相关问题:
- 什么是针对 powershell 的 x64 与 x86 可变性进行编程的最佳方法是什么? 这个问题涉及在 32 位和 64 位架构上运行的代码.我的问题涉及您希望确保脚本仅针对正确版本运行的情况.
- What is the best way to program against powershell's x64 vs. x86 variability? This question deals with code running against both 32-bit and 64-bit architectures. My question deals with the case when you want to ensure the script only runs against the correct version.
推荐答案
如果您的 shell 在 .NET 4.0 (PowerShell 3.0) 上运行:
If you're shell is running on .NET 4.0 (PowerShell 3.0):
PS> [Environment]::Is64BitProcess
True
这篇关于确定当前的 PowerShell 进程是 32 位还是 64 位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!