[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4688: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4690: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4691: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4692: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
Cheshire Cat Computing :: View topic - Power shell examples
Cheshire Cat Computing
http://mail.steveshipway.org/forum/

Power shell examples
http://mail.steveshipway.org/forum/viewtopic.php?f=11&t=1586
Page 1 of 1

Author:  JamieD [ Thu Jun 26, 2008 5:05 pm ]
Post subject:  Power shell examples

I converted my vbs scripts running under cscript to powershell. This improved data loss, improved speed and reduced the load on the system significantly. Huge CPU reduction

How to run PowerShell

Target[AK26-S125-VAL1_cpu]: `C:\WINDOWS\system32\windowspowershell\v1.0\PowerShell.exe C:\mrtg-2.14.5\mrtg-2.14.5\bin\vbscripts\PercentUsedCPU.ps1 10.X.X.X'

The blankvalues are place holders of value 0 since MRTG likes two values returned
Each script is sperated by *****************

*****************
# reports used space in %
# change C:\ to any other localdrive letter

$i = $args
$diskCStats = get-WmiObject -query "select Freespace, size, DeviceID from Win32_logicalDisk where DeviceID ='C:' " -computername $i
if ($diskCStats.DeviceID -eq "C:") {
$a = 100 - (100 * $diskCStats.Freespace/$diskCStats.size)
[math]::round($a,0)
$blankvalue = 0
}
$blankvalue


*****************

# Dual CPU 0 & 1
# change the values for a single CPU or CPU 2 & 3 etc

$i = $args
$colitems = get-WmiObject -query "select loadpercentage, DeviceID from Win32_processor where DeviceID ='CPU0' " -computername $i
if ($colitems.DeviceID -eq "CPU0") {write-host $colitems.loadpercentage}

$colitems = get-WmiObject -query "select loadpercentage, DeviceID from Win32_processor where DeviceID ='CPU1' " -computername $i
if ($colitems.DeviceID -eq "CPU1") {write-host $colitems.loadpercentage}

*****************


$i = $args
$colitems = get-WmiObject -query "select PagefaultsPersec from Win32_PerfFormattedData_PerfOS_Memory" -computername $i
$colitems.PagefaultsPersec
$blankvalue = 0
$blankvalue

*****************

#The WMI (size and freespace) properties are of type UInt64 and,
#unfortunately, some PowerShell operators don't support all types.
#[long] seems to work
# Used amount physical and virtual in %

$i = $args
$colitems = get-WmiObject -query "select AvailableKBytes from Win32_PerfFormattedData_PerfOS_Memory" -computername $i
$colitems1 = get-WmiObject -query "select TotalVisibleMemorySize from Win32_OperatingSystem" -computername $i
$colitems2 = get-WmiObject -query "select AllocatedBaseSize, CurrentUsage from Win32_pagefileUsage" -computername $i
[long]$a = $colitems.AvailableKBytes
[long]$b = $colitems1.TotalVisibleMemorySize
$c = $b - $a
foreach ($objItem2 in $colItems2) {
$PercentUsedPhysicalmemory = (100*($c/$colitems1.TotalVisibleMemorySize))
$PercentUsedVirtualmemory = (100*($objItem2.CurrentUsage /$objItem2.AllocatedBaseSize))
[math]::round($PercentUsedPhysicalmemory,0)
[math]::round($PercentUsedVirtualmemory,0)
}


# Terminal server active sessions
$i = $args
$colitems = get-WmiObject -query "select Activesessions from Win32_PerfFormattedData_TermService_TerminalServices" -computername $i
$colitems.Activesessions
$blankvalue = 0

$blankvalue

Page 1 of 1 All times are UTC + 12 hours [ DST ]
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/