I needed to create a firstname.lastname variable to automate an Outlook profile update via PRF. By default Windows has the %username% variable, which in my instance returns tuser- I need to set-up a new Outlook Profile for an account in a different forest which uses test.user, this script allows me to deploy the custom environment variable and therefore the PRF for the target mailbox.
I’ve given a few additional examples in the script, if you want to deploy via group policy add it as a user logon script.
The VBS Script
Set objShell = CreateObject("WScript.Shell") Set objUserEnv = objShell.Environment("USER") Set objADSysInfo = CreateObject("ADSystemInfo") Set objUser = GetObject("LDAP://" & objADSysInfo.UserName) ' This will create the variable %first.last% for the first.lastname objUserEnv("first.last") = objUser.givenName & "." & objUser.sn ' This will create the variable %first% for the first name objUserEnv("first") = objUser.givenName ' This will create the variable %last% for the surname objUserEnv("last") = objUser.sn ' This will create the variable %mail% for the primary mail address objUserEnv("cn") = objUser.mail
The variable is persistent, if you find that it doesn’t work for you, and you already have the command prompt open, you will need to close and reopen the command prompt for it to take effect.