none
Powershell all in one Pagefile location and move RRS feed

  • General discussion

  • I have many servers that still have the pagefile on the C drive and I am looking to have them moved to another drive to free up space. I have been able to get the list of where the location is, but I am lost as to how to have it moved to another drive. The servers all have the same letter drives, so it will be consistent for all. I would like to have it all done with one script. Any help would be greatly appreciated!
    • Changed type Bill_Stewart Monday, September 11, 2017 3:41 PM
    • Moved by Bill_Stewart Monday, September 11, 2017 3:41 PM This is not "scripts on demand"
    Thursday, July 13, 2017 6:21 PM

All replies

  • What does your script look like so far?

    -- Bill Stewart [Bill_Stewart]

    Thursday, July 13, 2017 6:26 PM
  • It is pretty much like one that I found here in the forums. I am too new at using PS to create my own. After this script, I am at a loss for what to do next.

    function Get-PageFileLocation()

     [CmdLetBinding ()]
     param(
      [Parameter(Mandatory=$False)]
      [String[]]$serverlist
     )
     #Get the list of servers
     $serverlist=get-content "C:\server.txt" -ErrorAction SilentlyContinue
        Write-Host "The array contents after reading the file are $serverlist"
     if($serverlist -eq $null)
     {
      $serverlist=hostname
     }
     $a=@()
     #Regular Expression to extract the page file location from the registry key
     $Regex="^\\.{3}(.*)"
     $Object=New-Object PSObject
     $Object1=New-Object PSObject
     foreach ($server in $serverlist)
     {
        Write-Host "Now we're working on $server"
      try
      {
       #Open the registry on multiple remote computers
       $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine',$server )
       $RegKeyPath= "SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management"
       $pageFileKey=$reg.OpenSubKey($RegKeyPath)
       $pageFileLocation=$pageFileKey.GetValue("ExistingPageFiles")
       if("$pageFileLocation" -match $Regex)
       {
        $pageFileLocation=$Matches[1]
        $Object | add-member Noteproperty ServerName $server -Force
        $Object | add-member Noteproperty PageFileLocation $pageFileLocation -Force
        $a+=$Object
       }
      } 
      Catch [Exception] # To capture the non reachable servers
      {
       [string]$ExcepMsg=$_.Exception.Message
       $Object1 | add-member Noteproperty ServerName $server -Force
       $Object1 | add-member Noteproperty PageFileLocation $ExcepMsg -Force
       $a+=$Object1
      }
     }
     Write-Output $a
    }

    Thursday, July 13, 2017 6:36 PM
  • Unfortunately this is not a place to ask for script customization. However, we can try to answer specific scripting questions. Please read this first to set your expectations:

    This forum is for scripting questions rather than script requests


    -- Bill Stewart [Bill_Stewart]

    Thursday, July 13, 2017 6:44 PM