This post is more than 5 years old
68 Posts
0
420818
January 12th, 2016 02:00
PowerShell to disable VMNet-Adapter
Hi,
I'm trying to find a way to disable a network adapter for particular VDI machines and I'm thinking to use Powershell to do that activity. But unfortuantly, the Powershell module to download the powershell is not available...
Highly appreciate your help.
No Events found!
Habibalby_083114
68 Posts
0
January 12th, 2016 04:00
Hi All,
I think I have to live with this script since it does the job.
$VMs = Get-Content C:\Scripts\VMs.txt
Foreach ($VM In $VMs)
{
Get-VM -Name $VMs | Get-VMNetworkAdapter | Disconnect-VMNetworkAdapter
Write-Host $VMS "Network Interface Has been disconnected"
Get-VM -Name $VMs | Get-VMNetworkAdapter | Connect-VMNetworkAdapter -SwitchName "VDI Networks"
Write-Host $VMs "Network Interface has been reconnected"
}
Hope it helps someone else...
lwhitelock
11 Posts
0
January 12th, 2016 02:00
What version of vWorkspace are you running?
Habibalby_083114
68 Posts
0
January 12th, 2016 02:00
Hi,
I'm running version 8.5..
This method on the Hyper-V will do, but I'm afraid that when the VMs disconnected and connected back, they will be connected with the old IP and they won't obtain IP from the new vLAN...
Get-VM "v-Win10-Template" | Get-VMNetworkAdapter | Disconnect-VMNetworkAdapter
Get-VM -Name "v-Win10-Template" | Get-VMNetworkAdapter | Connect-VMNetworkAdapter -SwitchName "VDI Networks"
I'm thinking of a way to renew the VMs IP without disconnecting the session from the end user..
Regards,
Hilbert_nl
17 Posts
0
January 12th, 2016 04:00
You're looking for a situation to refresh the DHCP lease for those VM's ?
Hilbert_nl
17 Posts
0
January 12th, 2016 04:00
Don't you have to loose the 's' from $VMs in the loop? Like this:
$VMs = Get-Content C:\Scripts\VMs.txt
Foreach ($VM In $VMs)
{
Get-VM -Name $VM | Get-VMNetworkAdapter | Disconnect-VMNetworkAdapter
Write-Host $VM "Network Interface Has been disconnected"
Get-VM -Name $VM | Get-VMNetworkAdapter | Connect-VMNetworkAdapter -SwitchName "VDI Networks"
Write-Host $VM "Network Interface has been reconnected"
}
Habibalby_083114
68 Posts
0
January 12th, 2016 05:00
Hi,
yes, that's right.. I'm looking for a way to refresh the DHCP lease for those VMs.
Regards,