Archive for September, 2018

Page File functions added to AZSBTools PowerShell module to Get, Set, Remove page file(s)


3 new functions have been added to the AZSBTools PowerShell module to view, create and modify page file settings on a Windows computer running Windows 2008/Windows 7 and above versions.

Get-PageFile

This simple function takes no parameters and returns a PS custom object for each page file that has the following 3 properties:

  • DriveLetter: such as ‘c’, or ‘e’, …
  • InitialSizeMB: such as 1024 (0 value indicates a system-managed page file)
  • MaximumSizeMB: such as 4096 (0 value indicates a system-managed page file)

For example:

Set-PageFile

This function changes the page file setting on a given drive letter to the specified initial and maximum size in MB. It takes one parameter that’s similar to the PS custom object returned by the Get-PageFile function.

The -PageFile parameter of the Set-PageFile function accepts a PS Custom Object containing the following 3 properties:

  • DriveLetter such as ‘c’
  • InitialSizeMB such as 1024 (0 value indicate system managed page file)
  • MaximumSizeMB such as 4096 (0 value indicate system managed page file)

This object can be constructed manually as in:

$PageFile = [PSCustomObject]@{
    DriveLetter   = 'c'
    InitialSizeMB = 0 
    MaximumSizeMB = 0 
}

or obtained from the Get-PageFile function

For example, to configure all page files on all drives to system managed size:

Get-PageFile | foreach { $_.InitialSizeMB = 0; $_.MaximumSizeMB = 0; $_ } | Set-PageFile

Note that changes to page file require a reboot to take effect. Rebooting is not part of this function.

Remove-PageFile

Finally this simple function will remove page file from a given drive. It takes one parameter being the drive letter such as ‘e’

The 3 functions can be used in user scripts to move page file from one drive to another. For example:

Set-PageFile -PageFile ([PSCustomObject]@{
    DriveLetter   = 'e' 
    InitialSizeMB = 0
    MaximumSizeMB = 0
})
Remove-PageFile 'c' -EA 0 


To use the AZSBTools PowerShell module which is available in the PowerShell Gallery, you need PowerShell 5. To view your PowerShell version, in an elevated PowerShell ISE window type

$PSVersionTable

To download and install the latest version of AZSBTools from the PowerShell Gallery and its dependencies, type

Set-PSRepository -Name PSGallery -InstallationPolicy Trusted

To trust the Microsoft PowerShell Gallery repository, then

Install-Module AZSBTools,AzureRM -Force -AllowClobber

AZSBTools contains functions that depend on AzureRM modules, and they’re typically installed together.

To load the AZSBTools, and AzureRM modules type:

Import-Module AZSBTools,AzureRM -DisableNameChecking

To view a list of cmdlets/functions in AZSBTools, type

Get-Command -Module AZSBTools

To view the built-in help of one of the AZSBTools functions/cmdlets, type

help <function/cmdlet name> -show

such as

help New-SBAZServicePrincipal -show

Advertisements