PageFile settings

O

OlivierT

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 Computer

J

Justin Rich

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" <[email protected]> wrote in message
news:[email protected]

> 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 Computer

B

Bob Landau

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 Computer

Top