VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Get Folder Details in output

Hi,

How can I get the Page file details folder

  $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine',$serverlist )

  $RegKeyPath= "SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management"

  $pageFileKey=$reg.OpenSubKey($RegKeyPath)

   $pageFileLocation=$pageFileKey.GetValue("ExistingPageFiles")

connect-viserver 172..10.10.10

$serverlist = get-folder Corporate | get-vm | Where {$_.Guest -match 'windows'} | where {$_.powerstate -eq "PoweredOn"}

$data = foreach ($server in $serverlist) {

    $physicalmem  = Get-WmiObject -computer $server -credential $credential Win32_ComputerSystem |

                    where {$_.TotalPhysicalMemory}

    $Pagefilesize = Get-WmiObject -computer $server -credential $credential Win32_pagefileusage |

                    where {$_.AllocatedBaseSize}

    New-Object psobject -Property @{

        Server   = $server

        RAM      = "$([math]::round(($physicalmem.TotalPhysicalMemory)/1GB,0)) GB"

        PageFile = "$([math]::round(($Pagefilesize.AllocatedBaseSize)/1024) ) GB"

        Location = $pageFileLocation

    }

}

$data

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Ok, try like this

$vms = Get-Folder -Name Corporate | Get-VM | Where {$_.Guest -match 'windows'} | where {$_.powerstate -eq "PoweredOn"}

foreach($vm in $vms){

    $physicalmem  = Get-WmiObject -computer $vm.Guest.HostName -credential $credential Win32_ComputerSystem |

        where {$_.TotalPhysicalMemory}

    Get-WmiObject -computer $vm.Guest.HostName -credential $credential Win32_pagefileusage |

        where {$_.AllocatedBaseSize} | %{

        New-Object psobject -Property @{

            Server   = $vm.Name

            RAM   = "$([math]::round(($physicalmem.TotalPhysicalMemory)/1GB,0)) GB"

            PageFile = "$([math]::round(($_.AllocatedBaseSize)/1024) ) GB"

            Location = $_.Name

        }

    }

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
12 Replies
LucD
Leadership
Leadership
Jump to solution

What do you actually mean/want to see with the Page File details folder?

Is there a link with PowerCLI in the question?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

I forgot to add the vcenter connection, now I have updated

I would like to get the Hostname, Folder, AllocatedMemory, PageFileSize, and PageFileLocation

0 Kudos
LucD
Leadership
Leadership
Jump to solution

It's still not 100% clear to me what you mean by PagefileLocation.

Is that folder or the full path to the pagefile?

Suppose the pagefile is C:\pagefile.sys, what do you want to see under the PagefileLocation property?

Is that C:\ or C:\pagefile.sys?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD, I would like to get the pagefile location as C:\pagefile.sys

Sorry for the confusion Smiley Happy

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Still not sure what the question is about, you have all the information.

Like this (I used the hostname in the guest OS, not the VM's displayname)

$vms = Get-Folder -Name Corporate | Get-VM | Where {$_.Guest -match 'windows'} | where {$_.powerstate -eq "PoweredOn"}

foreach($vm in $vms){

   $physicalmem  = Get-WmiObject -computer $vm.Guest.HostName -credential $credential Win32_ComputerSystem |

   where {$_.TotalPhysicalMemory}

   $Pagefilesize = Get-WmiObject -computer $vm.Guest.HostName -credential $credential Win32_pagefileusage |

   where {$_.AllocatedBaseSize}

   New-Object psobject -Property @{

   Server   = $vm.Name

   RAM   = "$([math]::round(($physicalmem.TotalPhysicalMemory)/1GB,0)) GB"

   PageFile = "$([math]::round(($Pagefilesize.AllocatedBaseSize)/1024) ) GB"

   Location = $Pagefilesize.Name

   }

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Hi LucD,

Thanks for your reply,

I am getting the output but with the below error

Get-WmiObject : User credentials cannot be used for local connections

At C:\get-page-info2.ps1:26 char:20

+ ... sicalmem  = Get-WmiObject -computer $vm.Guest.HostName -credential $c ...

+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], ManagementException

    + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

Get-WmiObject : User credentials cannot be used for local connections

At C:\get-page-info2.ps1:28 char:20

+ ... efilesize = Get-WmiObject -computer $vm.Guest.HostName -credential $c ...

+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], ManagementException

    + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

Get-WmiObject : Cannot validate argument on parameter 'ComputerName'. The argument is null or empty. Provide an

argument that is not null or empty, and then try the command again.

At C:\get-page-info2.ps1:26 char:44

+    $physicalmem  = Get-WmiObject -computer $vm.Guest.HostName -creden ...

+                                            ~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidData: (:) [Get-WmiObject], ParameterBindingValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetWmiObjectCommand

Get-WmiObject : Cannot validate argument on parameter 'ComputerName'. The argument is null or empty. Provide an

argument that is not null or empty, and then try the command again.

At C:\get-page-info2.ps1:28 char:44

+    $Pagefilesize = Get-WmiObject -computer $vm.Guest.HostName -creden ...

+                                            ~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidData: (:) [Get-WmiObject], ParameterBindingValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetWmiObjectCommand

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Is the station on which you run the script included in the list of VMs?

If yes, you can exclude that station, or add and If station for that case, and not use the Computer and Credential parameter on the WMI cmdlet.

You don't seem to have VMware Tools installed and running on all the VMs.

Is that correct?

If the hostname is the same as the VM's Displayname, you can change $vm.Guest.Hostname with $vm.Name.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Hi LucD,

As mentioned, I excluded the VM on which I am running the script, but now I am getting the below error

Method invocation failed because [System.Object[]] does not contain a method named 'op_Division'.

At E:\get-page-info2.ps1:47 char:18

+    PageSize = "$([math]::round(($Pagefilesize.AllocatedBaseSize)/1024)) GB"

+                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (op_Division:String) [], RuntimeException

    + FullyQualifiedErrorId : MethodNotFound

Method invocation failed because [System.Object[]] does not contain a method named 'op_Division'.

At E:\get-page-info2.ps1:47 char:18

+    PageSize = "$([math]::round(($Pagefilesize.AllocatedBaseSize)/1024)) GB"

+                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (op_Division:String) [], RuntimeException

    + FullyQualifiedErrorId : MethodNotFound

Method invocation failed because [System.Object[]] does not contain a method named 'op_Division'.

At E:\get-page-info2.ps1:47 char:18

+    PageSize = "$([math]::round(($Pagefilesize.AllocatedBaseSize)/1024)) GB"

+                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (op_Division:String) [], RuntimeException

    + FullyQualifiedErrorId : MethodNotFound

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Do you have VMs with more than 1 pagefile configured?

For example on the C- and D-partition.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Yes, LucD, in few VMs page file is configured on multiple drives and different drives rather than C:\

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Ok, try like this

$vms = Get-Folder -Name Corporate | Get-VM | Where {$_.Guest -match 'windows'} | where {$_.powerstate -eq "PoweredOn"}

foreach($vm in $vms){

    $physicalmem  = Get-WmiObject -computer $vm.Guest.HostName -credential $credential Win32_ComputerSystem |

        where {$_.TotalPhysicalMemory}

    Get-WmiObject -computer $vm.Guest.HostName -credential $credential Win32_pagefileusage |

        where {$_.AllocatedBaseSize} | %{

        New-Object psobject -Property @{

            Server   = $vm.Name

            RAM   = "$([math]::round(($physicalmem.TotalPhysicalMemory)/1GB,0)) GB"

            PageFile = "$([math]::round(($_.AllocatedBaseSize)/1024) ) GB"

            Location = $_.Name

        }

    }

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Superb, that worked...thank you very much Smiley Happy

0 Kudos