HI Guys,

This script will be useful to get the page file information and it will set according to our requirement / criteria. This is the first script in my life, bcoz of powershell i learned & completed within a week. Thanks to powershell inventor.

please post your comments, feedbacks so that i can change the sscript according to the requirements / suggestions. I required few sugestions, if any mistake i have done apologies(i am beginner in script) :)

Gana

 

PowerShell
Edit|Remove
Import-Module PSRemoteRegistry
$DebugPreference = "continue"
function get-hostinfo 

				{
	Begin {
		Write-output "Starting inventory Collection"
	}
	
	Process {
	$server = $_
	Write-Host $server
	$pingresult = Get-WmiObject -Query "SELECT * FROM Win32_PingStatus WHERE Address = '$server'" -ErrorAction Stop
	
	#creating a new object called computer
	$Computer = New-Object psobject
	Write-Debug $Computer
	if ($pingresult.statuscode -eq 0 )
		
		{
		trap {
		Write-Host -ForegroundColor Red "   Error connecting to server : " $server ". Please make sure that the server is online and that WMI Queries are enabled."
		continue
		}
		#$OS = Get-WmiObject -Query "SELECT * from win32_operatingsystem" -computername $server -ErrorAction Stop
		$OSResult = Get-WmiObject -Query "select * from win32_operatingsystem" -ComputerName $server -ErrorAction stop
	
		#the following section Adds properties to the computer Object 
$Serverreply = if ($pingresult.responsetime -gt 1)
{
 "Server is pingable"
}
else
{
"Server is not pingable"
}

	#Adding properties from ping result
	$Computer | Add-Member NoteProperty Name $server
	$Computer | Add-Member NoteProperty ServerResponse ($Serverreply )
	$Computer | Add-Member NoteProperty IPAddress ($pingresult.protocoladdress)
	
	if ($OSresult.caption -match 2003)
	{

	#Quering Wmi for certian properties to collect information for the computer
	$pagefile = Get-WmiObject -Query "select * from win32_pagefilesetting" -ComputerName $server -ErrorAction Stop 
	
	
	
	if ( $pagefile.count -ge 2) { 
	
	
	$PFInitialSize = ""
	#$PFInitialSize2 = ""
	$pagefile | ForEach-Object {  
	$PFInitialSize = ( $PFInitialSize +  $_.initialsize + "`n" ) }
	#Write-Debug (($PFInitialSize1).substring(0,3))
	#$PFInitialSize2 = ( $PFInitialSize2 +  $_.initialsize + ";" )
	#Write-Debug (($PFInitialSize2).substring(0,3))
	
	
	$PFMaximumSize = ""
	$pagefile | ForEach-Object { $PFMaximumSize = ( $PFMaximumSize + $_.maximumsize + "`n" ) }
	
	$PFDrive = ""
	$pagefile | ForEach-Object { ($PFDrive = $pfdrive + (($_.caption).substring(0,3)) + "`n" ) }
	
}
else {

	$PFInitialSize = ""
	$pagefile | ForEach-Object { $PFInitialSize = ( $PFInitialSize +  $_.initialsize  ) }
	
	$PFMaximumSize = ""
	$pagefile | ForEach-Object { $PFMaximumSize = ( $PFMaximumSize + $_.maximumsize  ) }
	
	$PFDrive = ""
	
	$pagefile | ForEach-Object { ($PFDrive = $pfdrive + ($_.caption).substring(0,3) ) }
	
}

$Computer | Add-Member Noteproperty PFInitialsize ( $PFInitialSize )
$Computer | Add-Member Noteproperty PFMaximumsize ( $PFMaximumSize )
$Computer | Add-Member Noteproperty PFDrive ($PFDrive)
$Computer | Add-Member Noteproperty PFCount ( $pagefile.Count )	
	
	#Nullifying Wmi Queries results from previous objects , to fix the problem of assigning previous Wmi Query values to offline servers	
	$RamResult=0
	$ModelResult=0
	$CpuResult=0
	$DiskResult=0
	$pagefile = 0
	$MemoryDumpfile = 0
	$MiniMemoryDumpfile = 0
	$WriteToSystemLog = 0
	$crashdumpinfo = 0
		
	#Quering Wmi for certian properties to collect information for the computer
	
	$RamResult = Get-WmiObject -Query "SELECT * from Win32_PhysicalMemory" -computername $server -ErrorAction Stop
	$DiskResult = Get-Wmiobject -Query "select * from Win32_logicaldisk" -ComputerName $server -ErrorAction Stop
	#$pagefile = Get-WmiObject -Query "select * from win32_pagefilesetting" -ComputerName $server -ErrorAction Stop 
	$DumpLoginfo = Get-RegValue -ComputerName $Server -Key SYSTEM\CurrentControlSet\Control\crashcontrol -value LogEvent -ErrorAction Stop 
    $DumpRebootinfo = Get-RegValue -ComputerName $Server -Key SYSTEM\CurrentControlSet\Control\crashcontrol -value AutoReboot -ErrorAction Stop 
    $Dumpenableinfo = Get-RegValue -ComputerName $Server -Key SYSTEM\CurrentControlSet\Control\crashcontrol -value CrashDumpEnabled -ErrorAction Stop 
    $Dumpfileinfo = Get-RegValue -ComputerName $Server -Key SYSTEM\CurrentControlSet\Control\crashcontrol -value DumpFile -ErrorAction Stop 
    $MiniDumpinfo = Get-RegValue -ComputerName $Server -Key SYSTEM\CurrentControlSet\Control\crashcontrol -value MinidumpDir -ErrorAction Stop 
    
	
	
	$ramcounter = 0
	$RamResult | ForEach-Object { $ramcounter = $ramcounter + $_.Capacity }
	$Computer | Add-Member NoteProperty RAMS ($ramcounter / 1048576)
	
	$bootfreespace = 0
	$bootdrivesize = 0
	$Logicalfreespace = 0
	$Logicaldrivesize = 0
	$LogicalDeviceID = ""
	$DiskResult | ForEach-Object {
							if ($_.drivetype -eq "3" -and $_.deviceid -like "C:")
							{
							$bootfreespace = $bootfreespace + $_.freespace
							$bootdrivesize = $bootdrivesize + $_.size
								Write-Debug $bootfreespace
							} 
						
							
	}
	$DiskResult | ForEach-Object {
	if (($_.drivetype -eq "3") -and ($_.deviceid -like "D:" -or "E:"))
							{
							$LogicalDeviceID = $_.deviceid
							$Logicalfreespace = $Logicalfreespace + $_.freespace
							$Logicaldrivesize = $Logicaldrivesize + $_.size
								Write-Debug $Logicalfreespace
								}
							}
							
	$Computer | Add-Member NoteProperty bootdrivefreeMB ([int]($bootfreespace / 1mb ))
	$Computer | Add-Member NoteProperty bootdrivesizeMB ([int]($bootdrivesize / 1mb ))
	$Computer | Add-Member NoteProperty LogicaldrivefreeMB ([int]($Logicalfreespace / 1mb ))
	$Computer | Add-Member NoteProperty LogicaldrivesizeMB ([int]($Logicaldrivesize / 1mb ))
	$computer | Add-Member noteproperty LogicalDeviceID ($LogicalDeviceID)
	
	#$pagefilesizeinitial = 0
	#$pagefilemaximum = 0
	
	
	#Adding properties for OS type and Version number
	$Computer | Add-Member NoteProperty OSType ($OSResult.caption)
	$Computer | Add-Member NoteProperty Servicepack ($OSResult.csdversion)

	# Memory Dump file location
	
	$Computer | Add-Member NoteProperty FullMemDumpFile ($Dumpfileinfo.Data)
	$Computer | Add-Member NoteProperty MiniMemDumpFile ($MiniDumpinfo.Data)
	
	#Memory Dump to system log
	
	#$syslogout = if ( $WriteToSystemLog -eq 1) { "Written in Event Log" }
	$Syslogout = if ( $DumpLoginfo.Data -eq 1) 
	{ 
		"Event Log enabled" 
		} 
		else 
		{ 
		"Event Log NOT enabled"
		}
	$Computer | Add-Member NoteProperty syslog ($Syslogout)
	
	$dumpinfo = if ( $Dumpenableinfo.Data -eq 0 ) 
	{
	"Memory Dump not set"
	}
	elseif ($Dumpenableinfo.Data  -eq 1)
	{
	"Complete Dump Set"
	}
	elseif ($Dumpenableinfo.Data  -eq 2)
	{
	"Kernel Dump Set"
	}
	elseif ($Dumpenableinfo.Data -eq 3)
	{
	"Mini Dump Set"
	}
	
	$Computer | Add-Member NoteProperty DumpType ($dumpinfo)
	
	$Computer | Add-Member NoteProperty OSVersion ($OSresult.caption)
	
	#Comparing Logical drive to set Memory dump

#if (($Logicalfreespace) -ge (($Ramcounter * 1.5) + ($Logicaldrivesize * 0.1)))
	
#	{
	#$key = "SYSTEM\CurrentControlSet\Control\crashcontrol"
	#$Setcrashdump = set-regdword -ComputerName $Server -key $key -value CrashDumpEnabled -Data 1 -Force -PassThru -Ping
	#$SetReboot = set-regdword -ComputerName $Server -key $key -value AutoReboot -Data 1 -Force -PassThru -Ping
	#$Setlogevent = set-regdword -ComputerName $Server -key $key -value LogEvent -Data 1 -Force -PassThru -Ping
	#$Setoverwrite = set-regdword -ComputerName $Server -key $key -value Overwrite -Data 1 -Force -PassThru -Ping
	#$Setsendalert = set-regdword -ComputerName $Server -key $key -value SendAlert -Data 1 -Force -PassThru -Ping
	#$SetDumpfile = set-RegExpandString -ComputerName $Server -key $key -value DumpFile -Data D:\MEMORY.DMP -Force -PassThru -Ping
	# MiniDump Directory not changed 
	#$newpageinitial = ($Ramcounter * 1.5)
	#$pagefile.initialsize = $newpageinitial
	#$pagefile.maximumsize =  ($newpageinitial * 3)
	#[void]$pagefile.put()
	#Set-RegMultiString -computername nawinapp604 -key $key -value PagingFiles -Data @("C:\pagefile.sys $newpageinitial $newpagemax") -Force -Ping

#	Write-Host " logical drive as space"
#	}
#	else
#	{
#	$Computer | Add-Member NoteProperty Memorydumpresult ("Logical drive as no space")
#	Write-Host "loical drive as no space"
#	}

	
	
	#OS loop ends
	
	}
	
	else
	{
	
	$Computer | Add-Member NoteProperty OSVersion ($osresult.caption)
	
	
	}
	
	}
	
	else
	{
	
	$Serverreply = if ($pingresult.responsetime -gt 1)
{
"Server is pingable"
}
else
{
"Server is not pingable"
}

	#Adding properties from ping result
	$Computer | Add-Member NoteProperty Name $server
	$Computer | Add-Member NoteProperty ServerResponse ($Serverreply )
	
	
	
	}
	
	
	Write-Output $Computer
	}	
		
	End {
	Write-host "end of Inventory Collection"
	}
	
				}
Get-Content c:\ps\comp1.txt | get-hostinfo | Select Name , ServerResponse , IPAddress , OSVersion , bootdrivesizeMB , bootdrivefreeMB , LogicaldeviceID , LogicaldrivesizeMB , LogicaldrivefreeMB , PFInitialSize , PFMaximumSize , PFCount , PFDrive , RAMS , FullMemDumpFile , MiniMemDumpFile , syslog , DumpType | Out-GridView 
# <<<<<<  Script execution Starts HERE  >>>>>>>		

#comment this part out if you want to create a connection to Active directory to get the computer objects
#connecting to AD to query computers in a security group named "servers"
#$servergroup=[ADSI]"LDAP://CN=Servers,DC=YourDomain,DC=dom" #Set your location for AD group containing servers
#$groupmembers=$servergroup.member

#Actual command being line (pipeline)

# you can use Get-hostinfo function in the following Ways
#$groupmembers | get-hostinfo | Select Name , IPAddress , Sitelocation , SrvModel , TotalStorageGB , RAMS , CpuMhz , ProcessorCores , PhysicalProcessors, Applist | Export-Csv C:\test\spiderresult.csv
#$groupmembers | get-hostinfo | Select Name , OSType , Servicepack ,  IPAddress , Sitelocation , SrvModel , TotalStorageGB , RAMS , CpuMhz , ProcessorCores , PhysicalProcessors , Applist | Export-Clixml c:\test\spiderobj.xml
#Get-Content c:\servers.txt | Select Name , IPaddress , Srvmodel | Export-csv C:\output.csv        "getting content from alocal file"
#$groupmembers | get-hostinfo | Select Name , OSType , Rams , Cpumhz  | export-clixml c:\compobjs.xml