Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

PageFile settings

181 views
Skip to first unread message

OlivierT

unread,
May 12, 2010, 10:34:01 AM5/12/10
to
Hi all,

I'm trying to manage PageFile on my Windows 2008 R2. The initial setup is
"Automatically manage paging file size for all drives".

I want to setup it with personal values. I wrote this script :

$RAM = Get-WmiObject -Class Win32_OperatingSystem | Select
TotalVisibleMemorySize
$RAM = ($RAM.TotalVisibleMemorySize / 1kb).tostring("F00")
$PageFile = Get-WmiObject -Class Win32_PageFileSetting

if ([Int]$RAM * 1.5 -ge 4096) { [Int]$SwapMax = 4096 }
Else { [Int]$SwapMax = [Int]$RAM * 1.5 }

[Int]$Actual_Swap = [Int]$PageFile.MaximumSize

If ($Actual_Swap -ne $SwapMax) {

$PageFile.InitialSize = $SwapMax
$PageFile.MaximumSize = $SwapMax

[Void]$PageFile.Put()

}


When I execute the script, i've got this error :

Property 'InitialSize' cannot be found on this object; make sure it exists
and is settable.
At C:\Configuration_2008.ps1:76 char:11
+ $PageFile. <<<< InitialSize = $SwapMax
+ CategoryInfo : InvalidOperation: (InitialSize:String) [],
RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound

Property 'MaximumSize' cannot be found on this object; make sure it exists
and is settable.
At C:\Configuration_2008.ps1:77 char:11
+ $PageFile. <<<< MaximumSize = $SwapMax
+ CategoryInfo : InvalidOperation: (MaximumSize:String) [],
RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound

You cannot call a method on a null-valued expression.
At C:\Configuration_2008.ps1:79 char:20
+ [Void]$PageFile.Put <<<< ()
+ CategoryInfo : InvalidOperation: (Put:String) [],
RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull


Does someone can help me ?

Olivier

Oisin (x0n) Grehan [MVP]

unread,
May 12, 2010, 4:18:03 PM5/12/10
to
On May 12, 10:34 am, OlivierT <Olivi...@discussions.microsoft.com>
wrote:

That class doesn't return anything on my machine (vista sp2) - I'm
betting it doesnt return anything for you either.

ps> (gwmi win32_pagefilesetting) -eq $null
True

-Oisin


Oisin (x0n) Grehan [MVP]

unread,
May 12, 2010, 4:23:03 PM5/12/10
to
On May 12, 4:18 pm, "Oisin (x0n) Grehan [MVP]" <ois...@gmail.com>
wrote:
> -Oisin- Hide quoted text -
>
> - Show quoted text -

it looks like this is the only pagefile related class that returns
anything [on my machine]:

PS C:\projects\powershell> gwmi Win32_PageFileUsage | fl *


Status :
Name : C:\pagefile.sys
CurrentUsage : 65
__GENUS : 2
__CLASS : Win32_PageFileUsage
__SUPERCLASS : CIM_LogicalElement
__DYNASTY : CIM_ManagedSystemElement
__RELPATH : Win32_PageFileUsage.Name="C:\\pagefile.sys"
__PROPERTY_COUNT : 9
__DERIVATION : {CIM_LogicalElement, CIM_ManagedSystemElement}
__SERVER : WHOD2113
__NAMESPACE : root\cimv2
__PATH : \\WHOD2113\root\cimv2:Win32_PageFileUsage.Name="C:\
\pagefile.sys"
AllocatedBaseSize : 8350
Caption : C:\pagefile.sys
Description : C:\pagefile.sys
InstallDate : 20090415143513.714542-240
PeakUsage : 65
TempPageFile : False
Scope : System.Management.ManagementScope
Path : \\WHOD2113\root\cimv2:Win32_PageFileUsage.Name="C:\
\pagefile.sys"
Options : System.Management.ObjectGetOptions
ClassPath : \\WHOD2113\root\cimv2:Win32_PageFileUsage
Properties : {AllocatedBaseSize, Caption, CurrentUsage,
Description...}
SystemProperties : {__GENUS, __CLASS, __SUPERCLASS, __DYNASTY...}
Qualifiers : {dynamic, Locale, provider, UUID}
Site :
Container :

Justin Rich

unread,
May 13, 2010, 11:32:19 AM5/13/10
to
I looked on a few machines and on some the win32_pagefilesetting returned no
results... and since i see some null references in your errors that might be
why.. you might want to validate its not null.

if it is null then in order to push the data in (not sure this is even a
good idea) you'll need to create the object... im no expert so im not really
sure how to do this.. but when i did a get-member on a good call it returned
this as the type

System.Management.ManagementObject#root\cimv2\Win32_PageFileSetting

which means you probably need to use reflection to create the management
object...

the other thing is, i havent tried to write to WMI and i know this can be
hit or miss... there is probably a way to tell but i dont know it, it does
say, from the get-member, that the properties are get/set so you should be
able to... either way, i think the first step would be to make sure you are
getting data returned.. with the testing i did it looks like a null pagefile
would cause these errors..

"OlivierT" <Oliv...@discussions.microsoft.com> wrote in message
news:C0D0BC2A-02A5-4154...@microsoft.com...

Bob Landau

unread,
May 14, 2010, 10:28:01 AM5/14/10
to
This is really quite confusing or at least I found it so. There are WMI
classes which is what you want in this case and WMI instances or objects
which is what you get back typically from GWMI

In your case there is not Win32PageFileSetting instance so nothing to set.

Either do this

$PageFile = Get-WmiObject -Query 'SELECT * FROM meta_class WHERE __this ISA
"Win32_PageFileSetting"'


or for v2 try Invoke-WmiMethod see help and examples.

0 new messages