Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Save an encrypted password to a file and retrieve it later for use in a script
- # Read-Host -AsSecureString | ConvertFrom-SecureString | Out-File password.txt
- if(-not $global:DefaultVIServers) {
- $user = 'ncoe\dsatech'
- $password = Get-Content 'Distributed Switch Migration\password.txt' | ConvertTo-SecureString
- $creds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user, $password
- Connect-VIServer ncoe-vcenter-01.ncoe.k12.ca.us -Credential $creds
- }
- Start-Transcript -Path 'Distributed Switch Migration\dis_switch_mig.txt'
- $virtual_machines = Get-VM -Location ncoe-vm10*
- foreach ($vm in $virtual_machines) {
- $virtual_nics = Get-NetworkAdapter -VM $vm
- foreach ($vnic in $virtual_nics){
- Write-Host "Migrating virtual machine '$($vm.Name)' network adapter '$($vnic.Name)' ... " -NoNewline
- $dist_pg = Get-VDPortgroup -name $vnic.NetworkName -ErrorAction SilentlyContinue
- if ($dist_pg){
- $result = Set-NetworkAdapter -NetworkAdapter $vnic -PortGroup $dist_pg -Confirm:$false
- if ($result) {
- Write-Host "success"
- } else {
- Write-Host "fail"
- }
- } else {
- Write-Host "fail"
- Write-Host "`nDistributed port group '$($vnic.NetworkName)' does not exist ($($vm.Name))`n" -ForegroundColor 'Red'
- }
- }
- }
- Stop-Transcript
Add Comment
Please, Sign In to add comment