如何使用 PowerShell 獲取頁面檔案設定?
頁面檔案,也稱為 Windows 作業系統中的虛擬記憶體檔案,是作業系統非常有用的一個部分。它透過將一些分頁檔案儲存在名為 Pagefile.sys 的檔案中來幫助減輕物理記憶體的負擔。通常,Windows 作業系統中的此檔案儲存在 C:\ 中,除非進行了修改。
您可以使用 Windows GUI 中的以下步驟檢查頁面檔案設定
系統屬性 → 高階 → 效能 → 設定 → 高階 → 虛擬記憶體 → 更改。

我們在上面的頁面檔案屬性影像中建立了一些塊和圓圈。我們將逐一檢視它們。
首先,要檢查頁面檔案是否自動管理,如第一個圓圈所示,我們將使用以下命令。
PS C:\> (Get-CimInstance Win32_ComputerSystem).AutomaticManagedPagefile
輸出
True

在上圖中,頁面檔案是自動管理的,因此輸出為 true。
其次,我們需要知道頁面檔案是系統管理還是自定義的,您需要使用 CIMInstance 或 WMI 類 Win32_PageFileSetting,但這裡的條件是,如果頁面檔案是自動管理的,則輸出將為 Null,因為在影像本身中您可以看到系統管理部分已停用。
因此,讓我們假設在一臺伺服器上停用了自動頁面檔案管理,當我們使用 Win32_pagefilesetting 命令時,我們將獲得以下詳細資訊。
Get-CimInstance Win32_PageFileSetting | fl *
輸出
Caption : c:\ 'pagefile.sys'
Description : 'pagefile.sys' @ c:\
SettingID : pagefile.sys @ c:
InitialSize : 0
MaximumSize : 0
Name : c:\pagefile.sys
PSComputerName :
CimClass : root/cimv2:Win32_PageFileSetting
CimInstanceProperties : {Caption, Description, SettingID, InitialSize...}
CimSystemProperties : Microsoft.Management.Infrastructure.CimSystemProperties在上面的輸出中,我們有 InitialSize 和 MaximumSize,它們指明瞭頁面檔案的自定義大小。如果兩者都為 0,則頁面檔案由系統管理。

第三,要了解頁面檔案驅動器及其當前和峰值使用情況,我們需要使用 CIMInstance 方法和類 Win32_PagefileUsage 類。
PS C:\Users\Administrator> Get-CimInstance Win32_PageFileUsage | fl *
輸出
Status :
Name : C:\pagefile.sys
CurrentUsage : 85
Caption : C:\pagefile.sys
Description : C:\pagefile.sys
InstallDate : 7/5/2020 12:01:30 PM
AllocatedBaseSize : 1024
PeakUsage : 127
TempPageFile : False
PSComputerName :
CimClass : root/cimv2:Win32_PageFileUsage
CimInstanceProperties : {Caption, Description, InstallDate, Name...}
CimSystemProperties : Microsoft.Management.Infrastructure.CimSystemProperties您可以看到 AllocatedBaseSize(即當前已分配)、TempPageFile(檢查是否建立了臨時頁面檔案)和頁面檔案的 CurrentUsage。

不幸的是,我們無法使用 PowerShell 獲取 Recommended 大小,因為它由系統管理,並且大小會根據系統需求而變化。
您可以使用 -ComputerName 引數在遠端計算機上獲取上面提到的所有頁面檔案設定。
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP