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
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
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 :
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...
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.