DSC resources for for configuration of a Windows computer. These DSC resources allow you to perform computer management tasks, such as renaming the computer, joining a domain and scheduling tasks as well as configuring items such as virtual memory, event logs, time zones and power settings.
Details of the scenario you tried and the problem that is occurring
I'm trying to utilize Azure VM temp disks for the pagefile but due to their small size (typically 2x RAM) and a limitation in Set-CimInstance (and similar methods), it's not possible to create anything of much use (e.g. only 1Gb on an 8Gb temp drive).
For example, splitting out the offending command in Set-PageFileSetting against an 8Gb drive with sufficient free space:
Set-CimInstance : Value out of range
At line:1 char:5
+ Set-CimInstance @setParams
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Win32_PageFileS...\pagefile.sys"):CimInstance) [Set-CimInstance], CimException
+ FullyQualifiedErrorId : HRESULT 0x8004102b,Microsoft.Management.Infrastructure.CimCmdlets.SetCimInstanceCommand
Suggested solution to the issue
All the CIM-based solutions seem to have a base class that is the underlying issue. To work around it, the only solution I've found is to directly set the registry key:
<#
.SYNOPSIS
Sets a new page file name.
.PARAMETER Drive
The letter of the drive containing the page file
to change the settings of.
.PARAMETER InitialSize
The initial size to set the page file to.
.PARAMETER MaximumSize
The maximum size to set the page file to.
#>
function Set-PageFileSetting
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[System.String]
$Drive,
[Parameter()]
[System.Int64]
$InitialSize = 0,
[Parameter()]
[System.Int64]
$MaximumSize = 0
)
# Using Set-CimInstance fails if pagefile exceeds 1/8th of the available disk space so we're switching to using direct registry key settings.
$pageFileName = Join-Path `
-Path $driveInfo.Name `
-ChildPath 'pagefile.sys'
$value = "$pageFileName $InitialSize $MaximumSize`n" # Even though it's a Reg_SZ_Multi, it's not double-null terminated
# TODO: Fix to support other drive values
Set-ItemProperty `
-LiteralPath 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management' `
-Name 'PagingFiles' `
-Type MultiString `
-Value $value `
-Force
}
Write-Verbose -Message ($script:localizedData.SettingPageFileSettingsMessage -f $Drive, $InitialSize, $MaximumSize)
}
The above is incomplete as it does not account for any other / pre-existing settings on another drive but that shouldn't be too hard to work out given the simple data structure of the registry key.
The DSC configuration that is used to reproduce the issue (as detailed as possible)
Using a system with a D: drive that is 8Gb in size:
Details of the scenario you tried and the problem that is occurring
I'm trying to utilize Azure VM temp disks for the pagefile but due to their small size (typically 2x RAM) and a limitation in Set-CimInstance (and similar methods), it's not possible to create anything of much use (e.g. only 1Gb on an 8Gb temp drive).
For example, splitting out the offending command in
Set-PageFileSetting
against an 8Gb drive with sufficient free space:Throws the following error:
Verbose logs showing the problem
Suggested solution to the issue
All the CIM-based solutions seem to have a base class that is the underlying issue. To work around it, the only solution I've found is to directly set the registry key:
The above is incomplete as it does not account for any other / pre-existing settings on another drive but that shouldn't be too hard to work out given the simple data structure of the registry key.
The DSC configuration that is used to reproduce the issue (as detailed as possible)
Using a system with a D: drive that is 8Gb in size:
The operating system the target node is running
Version and build of PowerShell the target node is running
Version of the DSC module that was used ('dev' if using current dev branch)
8.4.0