Pages

Tuesday, November 23, 2010

Unprotect or Delete VMware View Replicas

7/20/2012 Update: The below post pertains to pre view Composer 3.0. See this document for more information.

Ever have a VMware View Replica shown in vSphere Client but unable to move, edit, or delete it? I have.  First assume you really know what your doing and you need to modify it. Normally VMware View attempts to protect you from yourself and protects your replicas, even from you. But sometimes you may need to mofity them anyway and to do so you'll need to remove the protection.

To do this you will need to use the SviConfig Command on the View Composer server. The Syntax on it usage isn't to hard but the inventory path wasn't very clear. Thus the  problem is figuring out the syntax in order to remove the connection. As a Solution   This is a Powershell script that will display the correct syntax to remove the VMware View Protection from the replica. SviConfig usage for unptotectentity are as follows:
sviconfig -operation=unprotectentity
          -VcUrl=https://<VirtualCenter address>/sdk
          -Username=<VirtualCenter account name>
          -Password=<VirtualCenter account password>
          -InventoryPath=/<Datacenter name>/[vm|host]/<folder name>/<vm name>
          -Recursive=[true|false]

What I wrote is a powershell Script that generates the unprotect commands. The script requires the VMware vSphere PowerCLI to be installed but doens't have to be run from the View Composer server. This script only creates the commands, it does not execute sviconfig in anyway.  Instead it Creates the commands and puts them in a text file then shows you the text file.

Download UnprotectVmwareViewReplicas.ps1

Example Output
Output of Unprotect Replicas Commands 



UnprotectVmwareViewReplicas.ps1
##############################################################################
#
#  Purpose: Build Commands to remove Unprotection VMware View Replicas
#  Created By: Chris Towles
#  Site: http://www.christowles.com
#  When: 11/23/2010
#  Version: 1.1
#  Change List
#
##############################################################################
$vCenter = Read-Host "Please enter your Vmware VSphere IP or DNS Name"
$ViewComposer = Read-Host "Please enter ViewComposer IP or DNS Name"
$VMwareUserName = Read-Host "Please enter your Vmware VSphere UserName - shown in the in the command but is not used."
$VMwarePassword = Read-Host "Please enter your Vmware VSphere Password - shown in the in the command but is not used."

function Get-VMFolder ($VirtualMachine) {

 $FoundVMs = Get-VM $VirtualMachine -ErrorAction SilentlyContinue
 
 if ( $FoundVMs -ne $null) { 
   
  foreach($vm in $FoundVMs){
   
   $NetFolder = Get-View $vm.Folder
   
   $folderPath = @()
   $folderPath += $NetFolder.Name
   $folder = $null
   $folder = Get-Folder -Id $NetFolder.Parent | select -Index 0 -ErrorAction SilentlyContinue
   $folderPath += Get-ParentFolder $folder
   
   [string] $path = ""
   foreach ($part in $folderPath) {
    $path = "/$part" + $path
   }
   
   $path + "/$vm"
   
  }
 }
}

Function  Get-ParentFolder ($NetFolder) {
 $NetFolder.Name
 if($NetFolder.ParentID  -ne $null)
 {
  if($NetFolder.ParentID -match 'DataCenter-*'){
   $NetFolder.Parent.Name
  }
  else{
   $folder = Get-Folder -Id $NetFolder.ParentID
   Get-ParentFolder $folder
  }
 }
}

Connect-VIServer $vCenter
$VMPaths = Get-VMFolder "replica*"

$CommandString = @()
$CommandString += "CD C:\Program Files (X86)\VMware\VMware View Composer\"
$CommandString += ""

Write-host "Found the following Replicas"
foreach($vmpath in $VMPaths) {
 $vmpath
 $CommandString += "sviconfig -operation=unprotectentity -VcUrl=https://$ViewComposer/sdk -Username=$VMwareUserName -Password=$VMwarePassword -InventoryPath=$vmpath -Recursive=false"
 $CommandString += ""
}

$Tempfile = "$Env:TEMP\" + "unprotectentity.txt"
Remove-Item $Tempfile -Force -ErrorAction SilentlyContinue #delete file incase it already exists

####### Open the File to display the commands #######
Set-Content $Tempfile $CommandString
Start notepad  $Tempfile -Wait
Remove-Item $Tempfile -Force -ErrorAction SilentlyContinue

Links


Example Output
CD C:\Program Files (X86)\VMware\VMware View Composer\

sviconfig -operation=unprotectentity -VcUrl=https://vcenter2/sdk -Username=user -Password=pass -InventoryPath=///replica-5ef2d325-e627-476e-8c33-0b63e6adaaf5 -Recursive=false


5 comments:

  1. VC server connection established successfully.
    Looking for the entity on the VC server.
    SviConfig finished with an error. Exit code: 11
    Entity not found.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Really useful script. Thank you.

    ReplyDelete
  4. Resident applications inventive concept for making magnificent wrist watches. Probably ones own quite popular creases is definitely the chanel replica handbags Environmentally Dr Chronograph wide variety which will is able to combine legitimate precious time attempting to keep do the job through chronograph potential available during an chic model. Selecting an online business gathering as well as a communal achieve, ones own cool Resident Chronograph sit back and watch is definitely the appropriate supplement which will functions to create over ones own louis vuitton replica sale. That Resident Chronograph Environmentally Dr running watches can be delightfully built, prime quality and even cool running watches. With the new Eco-Drive concept from this sit back and watch, Resident creates a efficient products with the eco-friendly acutely aware individual. Ones own cool Resident Chronograph sit back and watch bills once more using lightweight to make sure you will never need to switch battery. When you put it on and reveal to the application to help you lightweight, that sit back and watch hublot replica uk to help you price and even do the job while not disruption. Prime quality is without a doubt showcased with the manufacturing of the Resident environmentally dr sit back and watch. Possible offers steel, which inturn, simply because we all assume is amazingly secure and even heavy duty. An important metal hublot replica band along with a flip the throughout form is without a doubt cartier replica everything that you can acquire on Resident Chronograph running watches, repeatedly an important feature in prime quality.

    ReplyDelete

Please leave a comment; someone, anyone!