Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import-module activedirectory
- Function Get-FileName($initialDirectory)
- {
- [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") |
- Out-Null
- $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
- $OpenFileDialog.initialDirectory = $initialDirectory
- $OpenFileDialog.filter = "All files (*.*)| *.*"
- $OpenFileDialog.ShowDialog() | Out-Null
- $OpenFileDialog.filename
- } #end function Get-FileName
- function PromptOldHost()
- {
- do{$error = 0
- write-host -NoNewline -ForegroundColor Red "Please Specify the Old Host: "
- $oldhost = Read-Host
- try
- {
- $info1 = Get-ADComputer $oldhost
- }
- catch
- {
- write-host "Could not find host. Please Try again"
- $error = 1
- }
- }while($error -eq 1)
- return $oldhost
- }
- function PromptNewHost()
- {
- do{$error = 0
- write-host -NoNewline -ForegroundColor Red "Please Specify the New Host: "
- $newhost = Read-Host
- try
- {
- $info2 = Get-ADComputer $newhost
- }
- catch
- {
- write-host "Could not find host. Please Try again"
- $error = 1
- }
- }while($error -eq 1)
- return $newhost
- }
- # *** Entry Point to Script ***
- write-host -ForegroundColor Red "Please select the File that contains a list of VMs you would like to migrate"
- $vmListFile = Get-FileName -initialDirectory "%HOMEDIR%"
- $vmList = Get-Content $vmListFile
- $oldhost = PromptOldHost
- $newhost = PromptNewHost
- Invoke-Command -ComputerName $oldhost -ScriptBlock {
- param($vl,$nhost)
- Foreach($machine in $vl)
- {
- Move-VM -Name $machine -DestinationHost $nhost -IncludeStorage
- }
- } -ArgumentList $mvList,$newhost
Advertisement
Add Comment
Please, Sign In to add comment