Tagged: Work

Sending an email with Task Scheduler using Powershell

Today at work I had a need to query a bunch of databases for a particular, er, thing, and then send that thing, if found, to myself via email.  I needed this to happen every morning. I decided, since we’re talking about a MS SQL and Windows 2003/2008 environment, that Powershell was the way to go.  And it was – until I popped it into scheduler.

When executed as a scheduled task, the email didn’t send.  Things before and after the email routine worked – the arrays populated, the log file filled – but the email didn’t go.  Firing it from a Powershell manually, everything went fine.

Being the stubborn arse I am, rather than get to Googling I started ripping things apart.  I had the query dump its results into a temp file that a separately scheduled script would open, parse, email and then clear.  Same result: run manually everything worked peachy. Scheduled, no email.

In the end the problem was irritatingly simple.  For some reason, when run as a scheduled task the script didn’t keep the socket open to the SMTP server long enough for a successful transmission.  I added a Start-Sleep -s 5 right after the SMTP command to give it a 5 second breather before continuing on.  Voila – email success.  How silly.

I think I’m going to like Powershell just fine.  Other than quirks like this, and getting used to the syntax, it’s easy enough – and it seems a lot of Windows specific stuff is streamlined, at least in comparison to my old go-to admin scripting languages.

Windows 7 Search Files And Programs

Rebuilt my laptop thanks to lazily allowing a rootkit to hit it and discovered that the Windows 7 Search Files and Programs function wouldn’t work.  No good, as this it is the default way I launch everything on my machine (no desktop icons FTW).  Turns out deleting one registry key does the trick:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\{EF87B4CB-F2CE-4785-8658-4CA6C63E38C6}\TopViews\{00000000-0000-0000-0000-000000000000}

It’s user specific, obviously.

Bootable USB installer for Win7

You’ll need a DVD or ISO of Win7 and have your USB drive plugged in.  Take note – this is going to erase it.  Bear in mind you can create a Win7 64 bit installer with this procedure, but you cannot create this install on a Win7 54 bit machine.  Good job Microsoft.
  1. Download DiskPart.
  2. Launch DiskPart by entering diskpart at the start menu or in a command prompt.
  3. Enter list disk.
  4. Enter select disk # where # is the appropriate disk number.
  5. Enter clean.
  6. Enter create partition primary.
  7. Enter active.
  8. Enter format fs=fat32 quick.
  9. Enter assign.
  10. Copy all files from the DVD or ISO to the USB drive and it’s good to go.

Run Line / Command Line Options

Here’s a nice list of run line/command line commands for Windoze:

Accessibility Controls access.cpl
Add Hardware Wizard hdwwiz.cpl
Add/Remove Programs appwiz.cpl
Administrative Tools control admintools
Automatic Updates wuaucpl.cpl
Bluetooth Transfer Wizard fsquirt
Calculator calc
Certificate Manager certmgr.msc
Character Map charmap
Check Disk Utility chkdsk
Clipboard Viewer clipbrd
Command Prompt cmd
Component Services dcomcnfg
Computer Management compmgmt.msc
Date and Time Properties timedate.cpl
DDE Shares ddeshare
Device Manager devmgmt.msc
Direct X Control Panel (If Installed)* directx.cpl
Direct X Troubleshooter dxdiag
Disk Cleanup Utility cleanmgr
Disk Defragment dfrg.msc
Disk Management diskmgmt.msc
Disk Partition Manager diskpart
Display Properties control desktop
Display Properties desk.cpl
Display Properties (w/Appearance Tab Preselected) control color
Dr. Watson System Troubleshooting Utility drwtsn32
Driver Verifier Utility verifier
Event Viewer eventvwr.msc
File Signature Verification Tool sigverif
Findfast findfast.cpl
Folders Properties control folders
Fonts control fonts
Fonts Folder fonts
Free Cell Card Game freecell
Game Controllers joy.cpl
Group Policy Editor (XP Prof) gpedit.msc
Hearts Card Game mshearts
Iexpress Wizard iexpress
Indexing Service ciadv.msc
Internet Properties inetcpl.cpl
IP Configuration (Display Connection Configuration) ipconfig /all
IP Configuration (Display DNS Cache Contents) ipconfig /displaydns
IP Configuration (Delete DNS Cache Contents) ipconfig /flushdns
IP Configuration (Release All Connections) ipconfig /release
IP Configuration (Renew All Connections) ipconfig /renew
IP Configuration (Refreshes DHCP & Re-Registers DNS) ipconfig /registerdns
IP Configuration (Display DHCP Class ID) ipconfig /showclassid
IP Configuration (Modifies DHCP Class ID) ipconfig /setclassid
Java Control Panel (If Installed) jpicpl32.cpl
Java Control Panel (If Installed) javaws
Keyboard Properties control keyboard
Local Security Settings secpol.msc
Local Users and Groups lusrmgr.msc
Logs You Out Of Windows logoff
Microsoft Chat winchat
Minesweeper Game winmine
Mouse Properties control mouse
Mouse Properties main.cpl
Network Connections control netconnections
Network Connections ncpa.cpl
Network Setup Wizard netsetup.cpl
Notepad notepad
Nview Desktop Manager (If Installed) nvtuicpl.cpl
Object Packager packager
ODBC Data Source Administrator odbccp32.cpl
On Screen Keyboard osk
Opens AC3 Filter (If Installed) ac3filter.cpl
Password Properties password.cpl
Performance Monitor perfmon.msc
Performance Monitor perfmon
Phone and Modem Options telephon.cpl
Power Configuration powercfg.cpl
Printers and Faxes control printers
Printers Folder printers
Private Character Editor eudcedit
Quicktime (If Installed) QuickTime.cpl
Regional Settings intl.cpl
Registry Editor regedit
Registry Editor regedit32
Remote Desktop mstsc
Removable Storage ntmsmgr.msc
Removable Storage Operator Requests ntmsoprq.msc
Resultant Set of Policy (XP Prof) rsop.msc
Scanners and Cameras sticpl.cpl
Scheduled Tasks control schedtasks
Security Center wscui.cpl
Services services.msc
Shared Folders fsmgmt.msc
Shuts Down Windows shutdown
Sounds and Audio mmsys.cpl
Spider Solitare Card Game spider
SQL Client Configuration cliconfg
System Configuration Editor sysedit
System Configuration Utility msconfig
System File Checker Utility (Scan Immediately) sfc /scannow
System File Checker Utility (Scan Once At Next Boot) sfc /scanonce
System File Checker Utility (Scan On Every Boot) sfc /scanboot
System File Checker Utility (Return to Default Setting) sfc /revert
System File Checker Utility (Purge File Cache) sfc /purgecache
System File Checker Utility (Set Cache Size to size x) sfc /cachesize=x
System Properties sysdm.cpl
Task Manager taskmgr
Telnet Client telnet
User Account Management nusrmgr.cpl
Utility Manager utilman
Windows Firewall firewall.cpl
Windows Magnifier magnify
Windows Management Infrastructure wmimgmt.msc
Windows System Security Tool syskey
Windows Update Launches wupdmgr
Windows XP Tour Wizard tourstart
Wordpad write

Using DSquery to glean all AD users

Full AD user list (run on the controller):

dsquery user -name * -limit 0 > output.txt

Admins (or members of any group you specify:

dsget group “CN=Domain Admins,CN=users,DC=domain,dc=com” -members > output.txt

I don’t use these often enough to remember.

Written by Comments Off on Using DSquery to glean all AD users Posted in Tech, Work Tagged with ,

Windows 7 Desktop Refresh

Interesting – my work machine, a Windows 7 64 bit box, suddenly stopped auto-refreshing the desktop.  Delete something off the desktop, and its icon remained until you right clicked and chose Refresh.  Save something to the desktop, and it wouldn’t appear until you did the same.  A co-worker had the same issue  and, after some serious Googling, found the culprit.

Teracopy.

Uninstall Teracopy, and viola!  Desktop behaves.  Too bad, as I love me some Teracopy.  I’m currently test driving the alternative SuperCopier, which is uglier than Tera but so far works well and doesn’t fark up the refresh.