Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- param([String]$ImportPath, [String]$SourceVC)
- # Getting vCenter Name and its credentials
- do {
- $user = Read-Host -Prompt 'Enter username for source vCenter'
- $pass = Read-Host -AsSecureString -Prompt 'Enter password for source vCenter'
- $cont = Read-Host -Prompt 'Type y to continue'
- } while($cont -ne 'y')
- $cred = New-Object –TypeName System.Management.Automation.PSCredential –ArgumentList $user, $pass
- # Connecting to vCenter
- Write-Host 'Connecting to' $SourceVC '..'
- Connect-VIServer -Server $SourceVC -Credential $cred | Out-Null
- if(!$DefaultVIServer) {
- Write-Host -Fore:Red 'Connection to vCenter' $SourceVC 'failed, exiting..'
- . (Join-Path -Path $scriptPath -ChildPath 'end.ps1')
- exit
- } else {
- Write-Host 'Connection to vCenter' $SourceVC 'succeeded'
- Write-Host
- }
- $csv = Import-CSV -Path $ImportPath | Where {$_.ServerName}
- $csv | % {
- $_.ServerName = $_.ServerName.Trim()
- $_.Username = $_.Username.Trim()
- $_.Password = $_.Password.Trim()
- $_.NewVlan = $_.NewVlan.Trim()
- $_.NewIP = $_.NewIP.Trim()
- $_.NewSubnet = $_.NewSubnet.Trim()
- $_.NewGW = $_.NewGW.Trim()
- }
- foreach ($vm in $csv){
- if($vm.PowerState -eq 'PoweredOff' or $vm.ExtensionData.Guest.ToolsRunningStatus -eq 'guestToolsNotRunning') {
- Write-Host Write-Host -Fore:Yellow $VM ' is powered off and the IP address of the VM will not be updated'
- } else {
- $nic = $vm | get-NetworkAdapter
- Set-NetworkAdapter -NetworkAdapter $nic -Portgroup $NewVlan
- (Get-NetIPAddress | where {$_.IPAddress -match "192.168.3.41" -and $_.AddressFamily -eq
- "IPv4"}).IPAddress
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement