Tag Archives: Scripting

Script: Delayed Sleep / Hibernate

I often sleep or hibernate my computer when I’m finished for the night so I can resume where I left off in the morning.

Problem: I was listening to some music I figured I’d like to fall asleep to. However, I don’t allow my pc to fall asleep on its own. So how could I (for just this one time) set a delayed Hibernate?

With a batch command naturally!

timeout /t 1200 /nobreak && rundll32.exe powrprof.dll,SetSuspendState 0,1,0

There you have it. Timeout + Hibernate/Sleep. A silly solution for a silly problem.

Script: Unhide Network Drive Folders

There is an infection going around that hides all folders on a network drive and sets them as system folders. Here is a script I wrote that will remove the hidden and system attributes all folders/files in a directory you specify.
It uses the “attrib -h -s” and is not recursive into subdirectories.

For complete removal of the infection, naturally scan all machines. Remove any rouge autorun.ini files and rouge .exe files on the network drive.

Download: UnhideNetworkDriveFolders.v1.zip

I haven’t tested on all system setups and naturally comes with no warranty.

Update 3/22/2013

This script can only be run against a folder ( C:/Production/Shared ) not against an actual mapped drive ( S:/ ) at this time.

Update 3/27/2013

Here is a quick list of things to check regarding cleaning up the infection/worm.

  • Scan all PCs with Malwarebytes
    • Cleanup the the startup items
    • Cleanup and rouge exe files located
      • C:\User\%Username%
      • C:\User\%Username%\AppData
      • C:\User\%Username%\AppData\Roaming
    • Find proccess the infection is running under. Example:  jjhhgg.exe
  • Network drives, Flashdrives, External Harddrives
    • Delete all *.exe that mimic a folder and have a folders name
    • Delete autorun.inf
    • Delete x.mpg
    • Deltee anything else odd, rouge .exe files, photos files with .exe extentions
    • CMD Prompt, browse to the folder and run
      • attrib -h -s
      • Note this only unhides files, not folders.
    • CMD Prompt, browse to the folder and run
      • FOR /F "tokens=*" %i IN ('DIR /A:D /b') do attrib -h -s "%i"
      • Note this only unhides folders, make sure to have the quotation marks

 

Grouping Mailboxes with PowerShell

Here is a snip-it of PowerShell Code I am using to group and count the number of mailboxes on an Microsoft Exchange Server 2008 using CustomAttribute1.

On our server we have a unique ID stored in the CustomAttribute1 for mailboxes that belong to different groupings. For example in the CustomAttribute1 we store the company ID, in CustomAttribute2 we may store the service level they pay for. We found the need to keep a count of the number of mailboxes belonging to different companies.

$CountMembers = @{}
Get-Mailbox | foreach-object {$CountMembers[$_.CustomAttribute1]++}
$CountMembers

Naturally from here we can append the | Out-File Report.txt to save to a txt file. Ideally I would like to export to a csv, however this data format doesn’t support that. I may look further into this in the future.

We can use this method to group mailboxes by any common attribute actually. Say the count the number of mailboxes on each database using $_.Database