Recently we migrated our Printserver from Windows 2003 R2 (yes, it was time…) to Windows 2012R2 and needed a smart and easy way to migrate existing printer mappings from the old to the new server. While migrating the printerserver itself was a very easy and straighforward task using Printbrm (took only about 10 mins!), the question how to migrate the mappings remained open. Doing some research on the net showed that it seemed to be best practice to do this using a logon script. A little bit of more searching brought up a very helpfull and handy PowerShell script which should to the trick. Since all our clients are at least Windows 7, PowerShell was available on clients and we were able to go on with this.

The script was good, but needed some minor tweaks to work well in our environment. For exmaple the script lacked to set the default printer. If you remove the old printer and add a new one you have to set the default printer again, this has been fixed in the version below.

It was also not possible to have 2 different names for the printserver so e.g. some users may have user FQDN (prinserver.domain.com) and some only the simple Name (printserver). To catch all this cases you can now specify more than one name for a print server and all printers will be replaced.

 

To run the script, simple copy the source code to a file on your PC and change the following lines to your need.

 

If you want a quite handy logfile where you can see how your migration is making progress. Change the following line to a path where all users can write.

 

Remove <# and #> from the following lines and run the Script once, to create the logfile with a header line. After the file has been created, add <# and #> again to avoid overwriting the file each time the script is running.

 

Here you can find the complete source code:

 

Description

Did you ever had the problem that traveling users were calling your ServiceDesk and said “I no longer can access this or that system since yesterday.”  where the reason for this was an expired Windows password? The reason for this is when users are on the road and only establish a VPN connection (which is not related to the AD password) to your site, they will not see the “Your password has expired” screen. If you have this problem or you just think the little notification warning you about your expiring password is not enough this script may help you.

With this script you can notify your users about expiring passwords via E-Mail so they will no longer forget to change their password. If they forget to change it, they can not blame you for not notifying them.

It’s designed to run as a scheduled task but you may also run it on demand. You have pleanty of option to customize the settings to fit your needs. You can have notifications in different languages e.g. you have a lot of subsidiaries.You can also specify the amount of notifications users will receive before the password is going to expire. The email can be easiely customized to fit your personell (or coorporate) design needs.

Requirements

Active Directory PowerShell Module (this is part of the RSAT (Remote Server Administration Tools)

Installation

Unpack the downloaded ZIP and place the files into a folder where you would like to store the script. No other installation is needed.

Execution Policy: Third-party PowerShell scripts may need that the PowerShell Execution Policy be set to either AllSigned, RemoteSigned, or Unrestricted. The default is Restricted, which prevents scripts – even code signed scripts – from running. For more information about setting your Execution Policy, see Using the Set-ExecutionPolicy Cmdlet.

Parameters

Allows you to specify a path other then the script directory for the config file.

Configuration

The script is configured using a configuration file. You can find detailed information on the New-PasswordReminder Config Options page. Please copy the configuration file the same folder as the New-PasswordReminder.ps1 file. A sample configuration is provided with the download you may only need to change the settings to fit your environment.

A basic configuration may look like this:

With this configuration you’ll notify your users at 00:00 UTC time when their password will expire in 1,3 or 7 days, the mail will be generated from the template “template_eng.txt”. In this configuration we have enabled the TestMode so all E-Mails will be sent to a specified address.

Template

The E-Mails will be created as HTML from a template. When creating the template you can use special tags, which will be replaced when the script processes the template so you have all the freedom of HTML (with the limitations of you mail client) to create your notifications.

[LastName] – LastName of the person

[FirstName] – FirstName of the person

[Days] – Days until the password expires

[FromAddress] – will be replaced with <SenderAdress>

[SenderName] – will be replaced with <SenderName>

[Phone] – will be replaced with <ContactPhone>

Scheduled Task

When creating a schedule task please use the following option for Powershell scripts under Actions:

Program/Script: %SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe

Arguments: -NoProfile -Noninteractive -command “. <PathToScript> -ConfigPath <PathToConfigFile>; exit $LASTEXITCODE”

<PathToScript> – Path to the Script including filename and extension

<PathToConfigFile> – Path to the config file including filename and extension

Exit Codes

The script will return the following exit codes on error.

1    PowerShell-Module not found
2    Config-File not found
3    LogPath is missing in configuration
4    LogLevel is missing in configuration
5    LogfilePath is empty in configuration
6    LogLevel is empty in configuration
7    Error in configuration, see log file

Download

v. 1.0 – 05.01.2017 – New-ExpiringPasswordReminder_v1.0.zip