For companies in the software development sector, creating new Windows virtual machines for employees can become a regular task. Employees who initialize these virtual machines often follow a list of common “best practice” adjustments to rename their machine and correct any system performance issues.
PowerShell is an efficient method of conducting all these common tasks in quick succession and providing a repeatable methodology that can be reused for each new virtual machine.
Note: The following commands are tested for Windows10 virtual machines using an admin-privileged PowerShell. I recommend creating a restore point of your virtual machine using a feature such as VMWare Workstation’s Snapshot.
Renaming the Virtual Machine PC and Local User Account
When distributing virtual machines across many employees, it is a best practice to rename the employee’s virtual machine so that it can be easily identified when working on large collaborative projects. The computer and local usernames can both be renamed using the following PowerShell commands:
# Renames the computer - be sure to replace the sample name
Rename-Computer -NewName "SampleName"
# Renames the local user - be sure to replace the company and sample name
Rename-LocalUser -Name "SampleCompanyName" -NewName "SampleName"
If the name of the current Local User is unknown, it can be viewed by searching for Computer Management using the start menu and navigating to “Local Users and Groups > Users”.
Figure 1: Location of the Local User within Computer Management
When changing the sample names to the appropriate fields for your needs, make sure there is no white space before or after the field. Using “ SampleName “ instead of “SampleName” may cause problems with password acceptance after a restart, locking you out of your virtual machine.
Performance Improvements
When working with limited computing resources, performance improvements can become vital on Windows virtual machines that run intensive programs. Two notable PowerShell commands are setting the Power Plan to High Performance and the removal of native Windows applications, which may bloat the system.
# Sets the Windows Power Plan setting to High Performance
powercfg.exe -SETACTIVE 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
# Removes all default Windows application packages
Get-AppxPackage -AllUsers | Remove-AppxPackage
This first command will set your virtual machine’s Power Plan setting to High Performance. The second command fetches all app packages (applications with a .msix or .appx file extension) for default Windows applications and removes them. This may take a while, as it will remove all applications such as the default calculator, photo viewer, Cortana, Xbox features, and more. System-crucial programs such as the File Explorer are untouched.
On some Windows11 and Windows10 host machines, virtual machine software such as VMWare Workstation experiences significant performance inhibitions due to the default program power throttling settings. If you experience this, you can disable power throttling for the application with the following command (executed in your host machine instead of the virtual machine):
# Disables power throttling for VMWare Workstation
powercfg /powerthrottling disable /path "C:\Program Files (x86)\VMware\VMware Workstation\x64\vmware-vmx.exe"
Quality of Life Improvements
For companies with many regional or international offices, employees in various time zones can quickly update the displayed time of their virtual machine by executing the following:
# Displays the current time zone
Get-TimeZone
# Lists all available time zones
Get-TimeZone -ListAvailable
# Set the time zone to the desired time zone name – be sure to replace the name with the appropriate time zone
Set-TimeZone "Sample Time Zone"
Common options for time zone names can be seen below. Replacing "Standard" with "Daylight" will correct the time to Daylight Savings Time.
Set-TimeZone "Eastern Standard Time"
Set-TimeZone "Pacific Standard Time"
Set-TimeZone "US Mountain Standard Time"
Set-TimeZone "Central Standard Time"
Disabling automatic Windows updates can save a significant amount of time during virtual machine system restarts and potentially save a virtual machine from incompatibility crashes after an unwanted feature update. To do this, run the following commands:
# Stop the automatic Windows update service
sc.exe stop wuauserv
# Disable the automatic Windows update service
sc.exe config wuauserv start=disabled
Single-Line Execution
Copying each line one-by-one is inefficient, so why not run all the commands at once? You can execute all of these changes in a single line by copying and pasting the text below. Adjust the fields, such as your name and time zone, before executing. When finished, your virtual machine will restart and apply the changes to your computer name and local username.
# Executes all commands in a single line
Rename-Computer -NewName "SampleName"; Rename-LocalUser -Name "SampleCompanyName" -NewName "SampleName"; Get-AppxPackage -AllUsers | Remove-AppxPackage; powercfg.exe -SETACTIVE 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c; Set-TimeZone "Sample Time Zone"; sc.exe stop wuauserv; sc.exe config wuauserv start=disabled; Restart-Computer
Figure 2: An example virtual machine PowerShell tweak to a new DMC virtual machine
Learn more about our Manufacturing Automation services and contact us for your next project.