Showing posts with label remote management. Show all posts
Showing posts with label remote management. Show all posts

Thursday, August 04, 2011

Caffeine - Utility to disable screen saver w/o interrupting input

I ran this on a machine I was RDP’d into to prevent the screen saver from appearing while I was logged in.  Handy.  And like other powerful utilities, potentially dangerous.  Not so much in an RDP session, though, because the console running the RDP client wouldn’t/shouldn’t(not a good idea) have this running, just the target host.  The author simulates an F15 keypress to make this work.  Didn’t know I had an F15 key.  Very nice.

Only 2 files inside the compressed download, and one is a README.

http://www.zhornsoftware.co.uk/caffeine/
Caffeine

imageIf you have problems with your PC locking or going to sleep, caffeine will keep it awake. It works by simulating a keypress once every 59 seconds, so your machine thinks you're still working at the keyboard, and won't lock the screen or activate the screensaver.

The icon is shown above - it's the leftmost one in the task tray, and this is all you see. Double-clicking the icon empties the coffee pot (that's what the icon is) and temporarily disables the program. Double-clicking it again refills the pot, and will keep your machine awake.

Monday, December 13, 2010

Free Space on all servers for all fixed drives? Done.

A while ago I posted on querying free disk space using WMI and batch.

I wouldn't query free disk space using batch anymore.  The PowerShell script I tweaked and currently use to query free disk space is displayed below.  The script truncates for readability – the rounding methods are commented out if that’s your preference:
# spaceused.ps1
# Lars-UT http://larsrasmussen.blogspot.com
(Get-Date -format 'yyyy-MM-dd hh:mm:ss').ToString() | Out-Default
$outData = @("")
$server = $args[0]
$dataFromServer = Get-WmiObject Win32_Volume -ComputerName $server | Select-Object SystemName,Label,Name,DriveLetter,DriveType,Capacity,Freespace

foreach ($currline in $dataFromServer) {
if ((-not $currline.name.StartsWith("\\")) -and ($currline.Drivetype -ne 5)) {
[float]$tempfloatcapacity = [math]::truncate($currline.Capacity/ 1000000000)
#[float]$tempfloatcapacity = [math]::round(($currline.Capacity/ 1000000000),1)
add-member -InputObject $currline -MemberType NoteProperty -name Capacity_in_GB -value "$tempfloatcapacity GB"

[float]$tempfloat = ($currline.Freespace / 1000000) / ($currline.Capacity / 1000000)
$temppercent = [math]::round(($tempfloat * 100),2)
add-member -InputObject $currline -MemberType NoteProperty -name FreePercent -value "$temppercent %"

[float]$tempfloatfreespace = [math]::truncate($currline.Freespace/ 1000000000)
#[float]$tempfloatfreespace = [math]::round(($currline.Freespace/ 1000000000),1)
add-member -InputObject $currline -MemberType NoteProperty -name Freespace_in_GB -value "$tempfloatfreespace GB"

$outData = $outData + $currline
}
}

$outData | Select-Object SystemName,Label,Name,Capacity_in_GB,Freespace_in_GB,FreePercent | sort-object -property Name | format-table -autosize

To run this against muliple servers just put the server names, one per line, in a text file and save that file. You'll then assign that file to a variable in PowerShell and loop through each line for each server:

PS C:\> $serverlist = Get-Content .\ServerNames-Prod.txt
PS C:\> foreach ($server in $serverlist) { .\spaceused.ps1 $server }


Here’s the pretty output!  Yep, those are sub-second times for querying multiple servers.



spaceused.ps1



Need to document this?  Use Start-Transcript.  I’ve seen auditors use it like so:



PS C:\> $strTimestamp =  [string](Get-Date -format "yyyy-MM-dd_hh-mm")
PS C:\> start-transcript .\ServerSpace-$strTimestamp.txt
PS C:\> foreach ($server in $serverlist) { .\spaceused.ps1 $server }
PS C:\> Stop-Transcript


Enjoy.

Friday, July 18, 2008

Querying Disk Space on Remote Servers using Batch with WMIC

Time to check the disk free space in GB and percentage on a server volume...

WMIC(Windows Management Instrumentation Command-line) makes another appearance!

Thanks to Tipsmark for this syntax (Response number 17 in this post). I added the /node switch and some error handling / usage to have this batch file work on remote machines.

@ECHO OFF
IF "%~1"=="" goto help
IF "%~2"=="" goto help

@SETLOCAL ENABLEEXTENSIONS
@SETLOCAL ENABLEDELAYEDEXPANSION

@FOR /F "tokens=1-3" %%n IN ('"WMIC /node:"%1" LOGICALDISK GET Name,Size,FreeSpace | find /i "%2""') DO @SET FreeBytes=%%n & @SET TotalBytes=%%p

@SET /A TotalSpace=!TotalBytes:~0,-9!
@SET /A FreeSpace=!FreeBytes:~0,-10!
@SET /A TotalUsed=%TotalSpace% - %FreeSpace%
@SET /A PercentUsed=(!TotalUsed!*100)/!TotalSpace!
@SET /A PercentFree=100-!PercentUsed!

IF %TotalSpace% LSS 0 goto error

@ECHO Total space: %TotalSpace%GB
@ECHO Free space: %FreeSpace%GB
@ECHO Used space: %TotalUsed%GB
@ECHO Percent Used: %PercentUsed%%%
@ECHO Percent Free: %PercentFree%%%

@SET TotalSpace=
@SET FreeSpace=
@SET TotalUsed=
@SET PercentUsed=
@SET PercentFree=
goto end

:error
echo.
echo *** Invalid server or drive specified ***
echo.
goto help

:help
echo.
echo diskfree.cmd
echo.
echo Queries remote server for free disk space.
echo Specify a MACHINENAME and a drive letter to be queried
echo.
echo Example: diskfree.cmd MACHINENAME c:
echo.
goto end


:end


Here's an example of the script being run with a target computer named 'LARS', checking for free space on the [F:] volume:





If parameters are not passed or passed incorrectly(wrong drive letter) the script outputs the following or similar: