Showing posts with label OS maintenance. Show all posts
Showing posts with label OS maintenance. Show all posts

Monday, October 12, 2015

Powershell Script - Set-UserPassword - Remotely sets local account passwords

Here's a great script to change passwords in bulk on many servers. I've added verbose and error output for logging purposes as well as time/date stamping for when actual password setting occurs.
PS C:\> 'server1','server2','Badserver' | Set-UserPassword -Username 'test' -Password 'pass123' -Verbose
VERBOSE: Processing server 'server1'...
VERBOSE: Connected to server 'server1'...
VERBOSE: Retrieved user objects from server 'server1'...
VERBOSE: Found user 'test' from server 'server1'...
10/12/2015 14:41:31 - Successfully changed password for user 'test' on server 'server1'
VERBOSE: Processing server 'server2'...
VERBOSE: Connected to server 'server2'...
VERBOSE: Retrieved user objects from server 'server2'...
WARNING: ERROR: No user 'test' on server 'server2'
VERBOSE: Processing server 'Badserver'...
WARNING: ERROR: Failed to connect to server 'Badserver'
PS C:\>


Thursday, June 25, 2015

Powershell Script - Get-LastBootTime - remotely find out when your servers where last rebooted

Here's another handy and simple function which lets you query a bunch of servers at once to find out when they were last rebooted.  It's taking advantage of Get-WmiObject and the root\civ2\Win32_OperatingSystem class.  For maximum parallelization, I've forced pipeline usage to first colapse the process block into a single array to create only one Get-WmiObject call.  This is significantly faster than the default pipeline behavior which is sequential, with 1000 servers completing under a minute (local LAN) vs sequential calls taking close to 10 minutes.

Here's it in action:

PS C:\> Get-Content .\serverlist.txt | Get-LastBootTime

Name      UpSince
----      -------
NOTSERVER Unknown             
SERVER001 6/20/2015 10:46:25 PM
SERVER002 6/20/2015 10:26:24 PM
SERVER003 6/20/2015 10:30:17 PM
SERVER004 6/20/2015 10:27:52 PM
SERVER005 6/20/2015 10:38:27 PM
SERVER006 6/20/2015 10:30:12 PM
SERVER007 6/20/2015 11:54:01 PM
SERVER008 6/20/2015 10:28:39 PM
SERVER009 6/20/2015 10:26:15 PM
SERVER010 6/20/2015 10:27:01 PM

Source Code:

Monday, June 22, 2015

Powershell script: Cleaning up C:\Windows\Installer directory - the correct way

This very simple script is built off Heath Stewart's VB Script which identifies the files linked for installed products that need to be kept.  My powershell wrapper simply takes his output and automates the deleting of what's not needed.  Usage is simple: drop the script in a temp directory, and run. It will create and run Heath's script which creates another file (output.txt) which is then read back in and parsed.  You'll see what's being removed and what's being kept.

It can be pushed as a scriptblock to remote servers using PS Remoting or PSexec.exe.

Enjoy!