This repository contains two PowerShell scripts for migrating local users, groups, and their memberships between Windows computers.
Exports all local users, groups, and their memberships from the source computer to a CSV file.
Imports users, groups, and memberships from the CSV file to recreate them on the target computer.
- Administrator privileges required on both source and target computers
- PowerShell 5.1 or later
- Windows 10/11 or Windows Server 2016+
# Run as Administrator
.\Export-UsersAndGroups.ps1 -OutputPath "C:\Migration\users.csv"Parameters:
-OutputPath(optional): Path where the CSV file will be saved. Default:.\UserGroupExport.csv
Example:
# Export to specific location
.\Export-UsersAndGroups.ps1 -OutputPath "D:\Backup\MyUsers.csv"
# Export to current directory (default)
.\Export-UsersAndGroups.ps1Copy the generated CSV file to the target computer.
# Run as Administrator
$SecurePass = ConvertTo-SecureString "TempPass123!" -AsPlainText -Force
.\Import-UsersAndGroups.ps1 -InputPath "C:\Migration\users.csv" -DefaultPassword $SecurePassParameters:
-InputPath(required): Path to the CSV file created by the export script-DefaultPassword(optional): SecureString password for imported users. If not specified, a random password is generated-SkipExisting(optional): Skip existing users/groups instead of updating them-GroupsOnly(optional): Create only groups without any users or group memberships-LogPath(optional): Path for the import log file. Default:./ImportLog.txt
Examples:
# Basic import with custom password
$SecurePass = ConvertTo-SecureString "SecurePass2024!" -AsPlainText -Force
.\Import-UsersAndGroups.ps1 -InputPath "users.csv" -DefaultPassword $SecurePass
# Import with random password generation
.\Import-UsersAndGroups.ps1 -InputPath "users.csv"
# Skip existing users and groups
.\Import-UsersAndGroups.ps1 -InputPath "users.csv" -SkipExisting
# Custom log file location
.\Import-UsersAndGroups.ps1 -InputPath "users.csv" -LogPath "C:\Logs\import.log"
# Create only groups without any users
.\Import-UsersAndGroups.ps1 -InputPath "users.csv" -GroupsOnly- Username
- Full name
- Description
- Enabled/disabled status
- Password settings (structure, not actual passwords)
- Group memberships
- Group name
- Description
- Group members
- All user-to-group relationships are preserved
- Supports adding both local and domain users to local groups
- Domain users can be specified as 'username' or 'DOMAIN\username' format
- Passwords are NOT migrated for security reasons
- All imported users receive the same default password or a randomly generated one
- Change default passwords immediately after import
- Review and verify all imported accounts before production use
- Creates only local users (not domain accounts), but can add domain users to local groups
- Built-in Windows accounts may have restrictions
- Some system groups may not be modifiable
- Password history and advanced security settings are not migrated
- Test first: Run on a test system before production migration
- Backup: Create system backups before running import
- Verify: Check all accounts and permissions after import
- Security: Change all default passwords immediately
- Documentation: Keep logs of the migration process
"Access Denied" errors:
- Ensure you're running PowerShell as Administrator
- Some built-in accounts cannot be modified
"User already exists" warnings:
- Use
-SkipExistingto skip existing accounts - Or allow the script to update existing accounts (default behavior)
Group membership errors:
- Verify the group exists before adding members
- Some system groups have restrictions on membership
- For domain users: Ensure the domain is accessible and the user account exists
- Domain user format issues: Try both 'username' and 'DOMAIN\username' formats
The import script creates detailed logs at the specified location (default: ImportLog.txt). Check this file for detailed information about any issues.
After import, verify:
- All expected users are present:
Get-LocalUser - All expected groups are present:
Get-LocalGroup - Group memberships are correct:
Get-LocalGroupMember -Group "GroupName" - Domain users in groups: Verify domain users appear correctly in group memberships
# On source computer (as Administrator)
.\Export-UsersAndGroups.ps1 -OutputPath "C:\Migration\company-users.csv"
# Transfer file to target computer
# Copy company-users.csv to target computer
# On target computer (as Administrator)
$SecurePass = ConvertTo-SecureString "TempPass2024!" -AsPlainText -Force
.\Import-UsersAndGroups.ps1 -InputPath "C:\Migration\company-users.csv" -DefaultPassword $SecurePass
# Verify import
Get-LocalUser
Get-LocalGroup
# Change passwords for all imported users
# (This should be done immediately for security)For issues or questions:
- Check the import log file for detailed error messages
- Verify administrator privileges
- Ensure PowerShell execution policy allows script execution:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
- v1.0: Initial release with basic export/import functionality
- Comprehensive error handling and logging
- Support for existing account updates
- Random password generation option