Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Adding a new PageFile on another drive than the system drive

Reply
 
Old 10-28-2008   #1 (permalink)
qu0vad1s


 
 

Adding a new PageFile on another drive than the system drive

Hi,

I have an issue in a script that i'm writing. Long story short my script
will need to write a new pagefile on the E:\ drive at some point, but I can,t
seem to get it through to the E:\ drive. I can only write to the C:\ drive
pagefile settings so far.

Here's a part of my code that works fine to have the C:\ drive pagefile
modified :

$ComputerName = get-content env:COMPUTERNAME
$colItems = Get-WMIObject -Class "Win32_PageFileSetting" -namespace
"root\cimv2" -computername $ComputerName
ForEach ($objItem in $colItems) {
$objItem.InitialSize = "5120"
$objItem.MaximumSize = "5120"
$objItem.Put()
}

I know that I can modify an existing pagefile on e:\ drive if it's already
there within the $colitems variable, but I need to create a new one as it
doesn't exist yet.

Can someone help me out?
Thanks!

My System SpecsSystem Spec
Old 10-29-2008   #2 (permalink)
qu0vad1s


 
 

RE: Adding a new PageFile on another drive than the system drive



"qu0vad1s" wrote:
Quote:

> Hi,
>
> I have an issue in a script that i'm writing. Long story short my script
> will need to write a new pagefile on the E:\ drive at some point, but I can,t
> seem to get it through to the E:\ drive. I can only write to the C:\ drive
> pagefile settings so far.
>
> Here's a part of my code that works fine to have the C:\ drive pagefile
> modified :
>
> $ComputerName = get-content env:COMPUTERNAME
> $colItems = Get-WMIObject -Class "Win32_PageFileSetting" -namespace
> "root\cimv2" -computername $ComputerName
> ForEach ($objItem in $colItems) {
> $objItem.InitialSize = "5120"
> $objItem.MaximumSize = "5120"
> $objItem.Put()
> }
>
> I know that I can modify an existing pagefile on e:\ drive if it's already
> there within the $colitems variable, but I need to create a new one as it
> doesn't exist yet.
>
> Can someone help me out?
> Thanks!
I forgot to mention that I've tried to modify it by setting the Name object
($objItem.name) to "E:\Pagefile.sys" but it gives me the following error :

Exception calling "Put" with "0" argument(s): "Exception calling "Put" with
"0" argument(s): "Access denied ""

Full modified code :

$ComputerName = get-content env:COMPUTERNAME
$colItems = Get-WMIObject -Class "Win32_PageFileSetting" -namespace
"root\cimv2" -computername $ComputerName
ForEach ($objItem in $colItems) {
$objItem.InitialSize = "500"
$objItem.MaximumSize = "600"
$objItem.Name = "e:\pagefile.sys"
$objItem.Put()
}

My System SpecsSystem Spec
Old 10-29-2008   #3 (permalink)
qu0vad1s


 
 

RE: Adding a new PageFile on another drive than the system drive



"qu0vad1s" wrote:
Quote:

>
>
> "qu0vad1s" wrote:
>
Quote:

> > Hi,
> >
> > I have an issue in a script that i'm writing. Long story short my script
> > will need to write a new pagefile on the E:\ drive at some point, but I can,t
> > seem to get it through to the E:\ drive. I can only write to the C:\ drive
> > pagefile settings so far.
> >
> > Here's a part of my code that works fine to have the C:\ drive pagefile
> > modified :
> >
> > $ComputerName = get-content env:COMPUTERNAME
> > $colItems = Get-WMIObject -Class "Win32_PageFileSetting" -namespace
> > "root\cimv2" -computername $ComputerName
> > ForEach ($objItem in $colItems) {
> > $objItem.InitialSize = "5120"
> > $objItem.MaximumSize = "5120"
> > $objItem.Put()
> > }
> >
> > I know that I can modify an existing pagefile on e:\ drive if it's already
> > there within the $colitems variable, but I need to create a new one as it
> > doesn't exist yet.
> >
> > Can someone help me out?
> > Thanks!
>
> I forgot to mention that I've tried to modify it by setting the Name object
> ($objItem.name) to "E:\Pagefile.sys" but it gives me the following error :
>
> Exception calling "Put" with "0" argument(s): "Exception calling "Put" with
> "0" argument(s): "Access denied ""
>
> Full modified code :
>
> $ComputerName = get-content env:COMPUTERNAME
> $colItems = Get-WMIObject -Class "Win32_PageFileSetting" -namespace
> "root\cimv2" -computername $ComputerName
> ForEach ($objItem in $colItems) {
> $objItem.InitialSize = "500"
> $objItem.MaximumSize = "600"
> $objItem.Name = "e:\pagefile.sys"
> $objItem.Put()
> }
>
Nevermind, I find my way around through the registry instead of WMI.

Code :

$RegKey = "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory
Management"
$KeyName = "PagingFiles"
$CMin = "500"
$CMax = "1000"
$EMin = "600"
$EMax = "1000"
$Value = "C:\Pagefile.sys $Cmin $CMax","e:\pagefile.sys $EMin $EMax"
set-ItemProperty -path $RegKey -name $keyName -value $Value
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Adding IDE Drive to New System with ATA / SATA Architecture Vista hardware & devices
Drive partition and relocating pagefile General Discussion
232G Drive Full With Pagefile!!!! Vista performance & maintenance
USB drive as pagefile drive Vista performance & maintenance
Can I use a USB Drive as my pagefile? Vista performance & maintenance


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46