Windows Vista Forums

PageFile settings
  1. #1


    OlivierT Guest

    PageFile settings

    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

      My System SpecsSystem Spec

  2. #2


    Justin Rich Guest

    Re: PageFile settings

    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" <OlivierT@newsgroup> wrote in message
    news:C0D0BC2A-02A5-4154-990B-4134B6A777EF@newsgroup

    > 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

      My System SpecsSystem Spec

  3. #3


    Bob Landau Guest

    RE: PageFile settings

    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.

    "OlivierT" wrote:

    > 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

      My System SpecsSystem Spec

PageFile settings problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Seven and pagefile JL Vista General 3 23 Dec 2009
Pagefile.sys RG Server General 2 04 Nov 2009
Cannot open Theme Settings, Display Settings, Screen Saver Settings, etc mitcho Vista performance & maintenance 3 13 Nov 2008
Pagefile encryption with EFS enabled but pagefile.sys is not green Luca Villa Vista file management 1 01 Oct 2007
Pagefile encryption with EFS enabled but pagefile.sys is not green Luca Villa Vista security 1 01 Oct 2007