Posts Tagged ‘Scripting’

Adding Terminal Services Information to User Reports

Saturday, February 4th, 2017

Add-ADTSInfo.ps1 adds TerminalServicesHomeDrive, TerminalServicesHomeDirectory, TerminalServicesProfilePath and AllowLogon as additional members returned by a query of Active Directory user objects.  As you may know, when looking at a user’s properties in the Active Directory Users and Computers MMC there is a tab for these fields.  However, if you look at the properties of a user object, these items simply aren’t there.  There are a few articles and scripts addressing this problem, and you will find that the only way to get the data is by binding to each individual user object and using the a method like this: $ADSIUser.psbase.InvokeGet(‘TerminalServicesProfilePath’).

My script differs from others in that you can pipe an object containing user objects with any properties, and it will add the fields listed above to your results.  I added sorting of the new resulting so that the property names are in order.  This is an advanced function with comment based help.

Script Text

Get Oldest Windows Event

Saturday, February 13th, 2016

Get-OldestEvent.ps1 is a PowerShell advanced function which returns the oldest event from a Windows computer event log, and will help you determine the rollover time for an event log by also returning the age of the record as a time span with the time created. Optionally you can return the entire oldest record with the age as an added member. Age is calculated from the time the script collects the information.  You must, of course, have admin rights to query remote event logs. Running locally requires that PowerShell be run elevated. Because it is an advanced function, it must first be loaded with “dot sourcing”.

Example: Get the time created and age for the oldest event in the Security log of this computer.
Get-OldestEvent

Example: Get the time created and age for the oldest event in the Application log of this computer.
Get-OldestEvent -eLog Application

Example: Get the oldest event from the Security log on MyServerName, plus Age of event.
Get-OldestEvent -ComputerName MyServerName -eLog security -ReturnAll

Script Text

Passwords for Password Resets

Monday, September 7th, 2015

I discovered that my script to generate passwords, RandomPW.vbs, isn’t popular with users because the passwords are random.  I have an even more complicated but unposted PowerShell version with the same issue.

I wanted to create something that was easier for the help desk and users.  Get-TempPW.ps1 is my answer to those objections.  This script is pretty well commented, so I won’t go into details about the code here.   What the script does is get a randomly selected word from the web, capitalizes a random letter within the word, then appends numbers and special characters to the end.  You can set the minimum word length and the number of numbers and special characters with variables within the code.  The default is and eight character word plus a number and special character.  The order of the numbers and special characters are randomized. An example password is “hypeRimmunization4&”.

Script Text

 

Test Whether Organizational Unit or Account Exists

Monday, September 7th, 2015

Here are two quick functions which I have recently found useful. The first tests whether a user account exists. It takes the Domain and Identity as arguments. Using the “Stop” error action with Try/Catch keeps it from showing any errors. You can do this with any of the AD cmdlets, such as Get-ADOrganizationalUnit, Get-ADComputer and others. The first example tests for the existence of a user account:

This tests whether an OU exists:

That VbScript worked in XP, Why Not Now?

Thursday, January 30th, 2014

Do you have a script that worked with your x32 XP computer, but no longer works in Windows 7 or 8 x64?  I am finding that some of the scripts I wrote have this problem.  Somethings may rely on an ActiveX control that was native to XP but not a later version.  What I am finding is that I have some scripts, such as this fragment fail:

A quick fix for this is to run the script with the X32 version of cscript or wscript.  You can try running the scripts with c:\windows\SysWow64\cscript.exe.  Otherwise, back to the debugger.

Laptop Return Reminder

Sunday, February 3rd, 2013

We love our users, yes we do!  Especially the ones who walk out the door with a laptop that they refuse to return.  Having a computer off the corporate network for an extended period of time can create problems with Active Directory,  some management software and some encryption software.  MakeLaptopWarning.vbs is a script which the admin runs before the laptop goes out the door.  It creates a reminder script on the laptop in the StartUp folder.  The user gets a countdown in days for when the laptop needs to be returned.

Make RDP files

Thursday, April 2nd, 2009

MakeRDPFiles.vbs is a vbscript based on the RDP History script posted earlier.  It take your RDP history and creates a folder with connection files for each of the systems you have previously connected to.  Rename from .txt to .vbs.

Remotely Enable Terminal Services and RDP

Thursday, April 2nd, 2009

You build a Windows 2003 server and forget to enable RDP.  Very annoying.  Or you want to RDP to a workstation, and it is not set up.  Very annoying.  EnableTS_RDP.vbs allows you to remotely enable RDP.

 

RDP History

Thursday, January 8th, 2009

RDPHistory.vbs creates a text file with a list of systems you ever connected to using RDP.  Rename from .txt to .vbs