[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

Software support and information
It is currently Sun Dec 21, 2025 8:52 pm

All times are UTC + 12 hours [ DST ]




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Power shell examples
PostPosted: Thu Jun 26, 2008 5:05 pm 
Offline
User

Joined: Thu Jun 12, 2008 11:51 am
Posts: 6
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


Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 12 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group