VIRT-006 · Script
Virtual Machine Network Configuration
Reports virtual machine network adapters with their connected networks and guest addresses, and can move an adapter to a different virtual switch or port group.
What it does
Report mode (default) lists every network adapter of the selected VMs: adapter name and type, MAC address, connected virtual switch (Hyper-V) or port group (VMware), VLAN (Hyper-V), whether it is connected, and the IP addresses the guest reports. Nothing is changed. Adapters on a running VM that are not connected to any network are flagged.
With -TargetNetwork set, the log lists exactly which adapters would be moved. Apply mode then connects them to -TargetNetwork: Hyper-V connects the adapter to the virtual switch named -TargetNetwork
- VMware: connects the adapter to the port group named -TargetNetwork (standard or
distributed) that is available on the VM's host The target is checked before anything changes. Moving a running VM to another network interrupts its connectivity. Guest IP settings (static addresses, DNS) are reported only and are never changed by this script. Runs silently. No prompts.
Requirements
Windows PowerShell 5.1+. Hyper-V: the Hyper-V PowerShell module. VMware: VMware PowerCLI installed by you. Guest IP addresses need Hyper-V integration services or VMware Tools running in the guest.
How to run it
- Run from: an admin workstation or scheduled task with the Microsoft modules installed and app sign-in configured
- This is an admin script for your Virtualization tenant, not a per-device endpoint script
- User interaction: none with app-only sign-in
- Schedule: run on demand, or weekly for reports
Settings
| Name | What it does | Options | Default |
|---|---|---|---|
| Platform | HyperV (default) or VMware. | HyperV, VMware | HyperV |
| Mode | Report (default) or Apply. | Report, Apply | Report |
| VMName | Virtual machine names, wildcards allowed, for example "LAB-PC-*". Empty = all VMs (report only). Required when TargetNetwork is set. | (none) | |
| AdapterName | Only change this adapter, for example "Network Adapter" (Hyper-V) or "Network adapter 1" (VMware). Empty = every adapter of the selected VMs. | ||
| TargetNetwork | Virtual switch (Hyper-V) or port group (VMware) to connect the adapters to, for example "Student-VLAN20". Empty (default) = report only. | ||
| ComputerName | Hyper-V only. Name of a remote Hyper-V host, for example HV01. Leave empty to use this computer. The account running the script needs Hyper-V administrator rights on that host. | ||
| Server | VMware only. vCenter Server or ESXi host name, for example vcenter.school.local. | ||
| CredentialPath | VMware only. Path to a credential file created with Get-Credential | Export-Clixml, for example C:\ProgramData\Runbookia\Secure\vcenter.xml. Create the file as the same account (for example SYSTEM) on the same computer that runs this script; Windows encrypts it so no other account can read it. Not needed with UseExistingSession. | ||
| UseExistingSession | VMware only. Reuse a vCenter Server or ESXi connection that is already open in this PowerShell session (from Connect-VIServer) instead of CredentialPath. | False | |
| IgnoreCertificateErrors | VMware only. Accept an untrusted or self-signed server certificate for this run only. Off by default; the PowerCLI setting on disk is not changed. | False | |
| ReportDir | Folder for CSV reports. Default C:\ProgramData\Runbookia\Reports. | C:\ProgramData\Runbookia\Reports |
Exit codes
- 0 = Report done with no disconnected adapters, or all changes made
- 1 = Disconnected adapters found, target network not found, a named VM was not found, or a change failed
- 2 = Script error (missing module, connection failed)
Testing steps
- Run it first with the mode set to Report on one test account or small group. Nothing is changed in that mode.
- Read the log and confirm the planned changes are what you expect.
- Run your chosen settings on the same test target and confirm the result.
- Check the exit code: 0 = OK, 1 = needs attention, 2 = error (see log), 9 = this copy is past its Valid until date.
- Roll out to a small group next, then everyone.
Rollback steps
Report mode changes nothing. To undo a move, run again in Apply mode with -TargetNetwork set to the original switch or port group listed in the Network column of the CSV report taken before the change.
Version and change log
| Version | Date | Changes |
|---|---|---|
| 1.0.0 | November 2026 | First release. |