Core Facility Bioimaging
print

Links and Functions

Breadcrumb Navigation


Content

Moving Users from old to new microscope computer

Problem: A microscope is getting a new computer or a new operating system, provided by the microscope manufactuer. This means that the operating system and the microscope control software are installed from scratch. All active users have to be installed again. Which may keep Core Facilty staff busy for weeks if several are replaced at the same time.

Attempted solution: users and their names as well as their microscope software settings on C:\ are extracted from the old system and copied to the new system. This is done semi-automatically with scripts as outlined below. 

We need this to update Leica microscopes only (LAS-X 3.X) from Windows 10 to Windows 11, some with new, Win 11 compatible hardware, some on the same hardware. The transfer of users to a new system should work for any type of new Windows installaton. The Leica specific subfolder in the respective scripts would have to be adapted however to make it work with systems from other vendors. 

Please note: As of now this guide is a suggestion! It is not yet tested. This note will be deleted once it was successfully applied. 

The scripts used in this guide were generated with the help of ChatGPT.

The following steps are performed:

  1. Generate a csv file with all the users that have to be moved to the new computer.
  2. Send all users of old computer e-mail, ask if they still need the account or not. Adapt csv file accordingly. 
  3. Use that csv file to copy relevant Leica settings of users to server or external drive.
  4. On the new computer, generate user accounts from csv file with temporary passwords. Enable "user must change password". 
  5. Copy Leica user settings files to respective user subfolder
  6. Send users their temporary password by e-mail

csv stands for "coma separated values". It is a text file that can be edited with any text editor, e.g. notepad or Notepad++.

Scripts for Download:

Please read the detailed explanations below before running the scripts. Use them at you own risk. No warranty!

Note: This web server does not allow storage of files with the ps1 script ending (for powershell version 1). Therefore .txt is added to each file. To run the script, delete ".txt" and replace the "_" before ps1 with a "." (a dot). You can do this during download or after you saved the files to the local disk. To download, right-click and select "Save Target as.."

To be run on the old computer (3 scripts): 
ExportUsers_Last6Months.ps1 || ExportUsers_All.ps1 || CopyLeicaSettings.ps1

To be run on the new computer (2 scripts):
CreateLocalUsers.ps1 || RestoreLeicaSettings.ps1

The scripts are essentiall text files that can be modified with any editor, e.g. notepad or Notepad++. The latter color codes the script, e.g. to distinguish comments from code and generally make the code readable more easily. 

Step 1: Generating a csv file with all the users that have to be moved to the new computer.

Strategy:

  • Run script ExportUsers_Last6Months.ps1 that generates a csv file Users_Last6Months.csv with all users that logged in over the last 6 months. 
  • Run script ExportUsers_All.ps1 that generates a csv Users_All.csv file with all current users.
  • Compare the two csv files to see if any users need to be copied from file 2 to file 1. Possibly some users that were active in the last 6 months can be removed. Remove any admin accounts that are in the file. Possibly fix Full Name, if not configured before. 
  • Change the temporary password to unpredictable values and so that everybody has a different one. Save the modified csv file as C:\Temp\Users.csv. That is the location and name where the script in step 3 will look for it. 

 

The two scripts create csv files formated as follows:

Name,FullName,Password,LastUseTime
mueller,Max Müller,StartPasswort123!,2026-06-14 08:17:52
schmidt,Anna Schmidt,StartPasswort123!,2026-04-21 13:55:08
meier,Peter Meier,StartPasswort123!,2026-01-30 09:11:44

In the files that the scripts produce, the passwords that will be used for the new computer (StartPasswort123!) are the same for everyone. Thus it needs to be changed manually. 

To run a script: 

  • Right-click on the link above and use "save as" to download the file. Make sure the file ending is .ps1 (see above)
  • Right-click on a Powershell Icon and select "run as administrator". (If you don't to this the shell will have no administrator rights, even if you are logged in as administrator!)
  • In the shell, change to the directory where the script file is saved and start the script with  ./ExportUsers_Last6Months.ps1

Step 2: Finalize the csv File

Optional: Check back with users in Users.csv and those not included if they still need the account in the future. Modify Users.csv accordingly.

Save a copy as MICROSCOPENAME-Users.csv on the server. This copy should contain the altered startpasswords.

Step 3: Copy Leica user settings on old computer to a temporary location

In a standard configuration, the Leica user files (e.g. sequential settings) are stored in 
C:\%username%\AppData\Roaming\Leica Microsystems\LAS X
AppData is a hidden folder and therefore may not be visible in the File Explorer. 

The script CopyLeicaSettings.ps1 will copy those files from all users listed in C:\Temp\Users.csv (see previous steps) to a folder E:\OldUsers, as in E:\OldUsers\<username>\AppData\Roaming\Leica Microsystems\LAS X

To change the location of users.csv or the target directory, the two respective lines at the beginning of the script 
$CsvFile = "C:\Temp\Users.csv"
$DestinationRoot = "E:\OldUsers"
have to be changed. 

A log file is created as E:\OldUsers\CopyLeicaSettings.log

Note 1: This script uses robocopy /MIR. The parameter MIR deletes everything in the target that is not present in the source. This may lead to unexpected results if the script is run twice on the same system with different Users.csv. If you need to run the script again, best delete the content of the target directory first. 

Note 2: If you are not sure that you have identified all the users that need to be migrated you can use Users_All.csv instead to copy the Leica settings from all users, to be on the safe side. You then can create additional users later and copy the Leica folder manually to the respective location in the user directory. 

Step 4: Create Users from csv File on new Computer

The Users.csv file from above is copied to the new computer to C:\Temp\Users.csv and used by the script CreateLocalUsers.ps1 to create those users on the new computer. This script does the following. 

  • Reads the Users.csv file
  • Creates a log file (Start-Transcript)
  • Skips users that already exist
  • Creates local user accounts
  • Uses the FullName value from the CSV file
  • Uses the password provided in the CSV file
  • Explicitly adds the user to the local Users group (language-independent by using the SID)
  • Configures the user account to require a password change at first logon (but see below)
  • Displays a summary at the end of the script

 The location of Users.csv can be adapted at the beginning of the script in the line 
$CsvFile = "C:\Temp\Users.csv"
Start the script in a Powershell with admin rights (see above how to do that). 

Note: Activating the setting "User must change password on next log on" may or may not work dependent on the exact windows version.

Alternative A: For the created users, check if checkmark in the Computer Administration->Local users and groups->Users ->right click->preferences of user is set. If not set it manually.

Alternative B: To generally check if the above script can activate the setting, run the following commands in Powershell (admin rights):
net user TestUser Test123!
net user TestUser /logonpasswordchg:yes

If TestUser then has the respective checkmark in the Computer Administration->Local users and groups->Users ->right click->preferences of user, the script will run as expected. If not, the  "change password on next log on" has to be set manually for each user. Delete TestUser afterwards. 

Step 5: Copy Leica user settings files to respective user subfolder on new computer

This step assumes, that the user was created as described above, but the user did not log in yet! If a login of the user did happen, this script may overwrite settings or possibly confuse windows in other ways. 

I strongly discourage to use this script for admin accounts, to avoid any such problems. 

This script assumes that users.csv is in C:\Temp\Users.csv and the copied Leica settings files are in E:\OldUsers. This can be adapted at the beginning of the script.

The script does the following:

  • Reads the Users.csv file to identify relevant users
  • Restores the complete LAS X directory for those users to the correct position (if they are present in the source, per default E:\OldUsers).
  • While doing so, create the target folder structure as required
  • Check whether the source data and the user account exist
  • Create a log file

Step 6: Send users their temporary password

Send an individual e-mail to all users from Users.csv with the temporary password and ask them to change it on the next log in. Ask them to report any problems they might encounter. If users have accounts on more than one processed computers, possibly send passwords of all of them in one mail. 


Service