Quantcast
Channel: VMware Communities : Discussion List - VMware PowerCLI
Viewing all 14549 articles
Browse latest View live

Can't see several network counters like net.throughput.usage.vm.average

$
0
0

I refered to this KB, and change collection level for several network counter.

VMware KB: Changing the collection level for Storage DRS and SIOC data counters in vSphere 5.0 Update 1 using the Le…

 

then level became 1.

Get-PxCounterLevelMapping  | ? {$_.Name -match "net.throughput.usage" }

 

Name                          AggregateLevel                PerDeviceLevel                Server

----                          --------------                --------------                ------

net.throughput.usage.average  1                             1                             Server1

net.throughput.usage.vm.av... 1                             1                             Server1

net.throughput.usage.nfs.a... 1                             1                             Server1

net.throughput.usage.vmoti... 1                             1                             Server1

net.throughput.usage.ft.av... 1                             1                             Server1

net.throughput.usage.iscsi... 1                             1                             Server1

net.throughput.usage.hbr.a... 1                             1                             Server1

 

host1 is 5.1.* ESXi Host.

C:\> Get-VMHost host1 | Get-StatType -Interval 1800 | ? {$_ -match "net" }

net.usage.average

net.usage.minimum

net.usage.maximum

net.packetsRx.summation

net.packetsTx.summation

net.received.average

net.transmitted.average

net.throughput.provisioned.average

net.throughput.usable.average

net.throughput.usage.average

net.throughput.contention.summation

net.throughput.packetsPerSec.average

net.throughput.usage.vm.average

net.throughput.usage.nfs.average

net.throughput.usage.vmotion.average

net.throughput.usage.ft.average

net.throughput.usage.iscsi.average

net.throughput.usage.hbr.average

net.droppedRx.summation

net.droppedTx.summation

net.bytesRx.average

net.bytesTx.average

net.broadcastRx.summation

net.broadcastTx.summation

net.multicastRx.summation

net.multicastTx.summation

net.errorsRx.summation

net.errorsTx.summation

net.unknownProtos.summation

 

host2 is 5.5.* ESXi Host.

C:\> Get-VMHost host2 | Get-StatType -Interval 1800 | ? {$_ -match "net" }

net.usage.average

net.usage.minimum

net.usage.maximum

net.packetsRx.summation

net.packetsTx.summation

net.received.average

net.transmitted.average

net.droppedRx.summation

net.droppedTx.summation

net.bytesRx.average

net.bytesTx.average

net.broadcastRx.summation

net.broadcastTx.summation

net.multicastRx.summation

net.multicastTx.summation

net.errorsRx.summation

net.errorsTx.summation

net.unknownProtos.summation

 

For the counter like net.throughput.usage.vm.average, I can't see in host2, anyone know reason?


How to script storage profile for new VM

$
0
0

Hey all,

 

I have a pretty long script that I've been putting together so that our operations folks can provision new VMs.  I prompt for a series of questions for things such as VM name, cluster, VLAN, hardware specs, OS/template, etc.  I'm using LucD's method to create a temporary copy of an OS Customization Specification to insert a static IP address.  I have everything working except I can't figure out how to script this dropdown:

 

storageprofiledropdown.jpg

 

vSphere 5.0, no VCD.  Seems like it should be pretty straight forward, but I can't find anything on how to do this.  It would be nice to choose this in the New-VM cmdlet somewhere, just like using the GUI.  Any ideas?

shutdown host and VMs in the vcenter via SDK perl script

$
0
0

Hi all:

I want to shutdown the host and all the VMs  on the pointed host in the vcenter though the perl script(as attachment):

 

shutdownESXi_vcenter.pl --server vcenter_IP --username vcenter_username --password  vcenter_password --host "needToShutdownhost_IP"

 

The perl script run successfully  when the host VM Startup/Shutdown settings are enabled, the host and VMs can be shutdown gracefully

but it fail if the host VM Startup/Shutdown settings are disabled (when the Cluster in the HA, the  host VM Startup/Shutdown settings are disabled by forcely)


I hope the VMs can be shut down by VM tools whenever the  host VM Startup/Shutdown settings are enable or disable, how can I modify the script?

for example: shut down VMs with VMTools running on an HA host,when host VM Startup/Shutdown settings are disable.

Get-VirtualSwitch, Get-VirtualPortGroup, relating VMName to Portgroup to vSwitch

$
0
0

I'm having some issues trying to relate a VM-Name to Portgroup to vSwitch to vmnics

 

Within the vCenter Desktop Client, I can see that (under a given blade server/ESXi host, under network configuration summary):

  1. $VMName is under Portgroup-A which is under vSwitch0 (uplink adapters vmnic0 and vmnic1)
  2. $VMName is also under Portgroup-B which is under vSwitch1 (uplink adapters vmnic2 & vmnic3)

 

However, when running the PowerCLI scripts to retrieve this information --

  • Get-VirtualSwitch -VM $VMName
    • It does see vSwitch0
    • It does NOT see vSwitch1

 

  • Get-VirtualPortGroup -VM $VMName
    • can see Portgroup-A and Portgroup-B

 

Any ideas on how to get Get-VirtualSwitch to see the other associated vSwitch1? or get the associated vSwitch with a specified PortgroupName?

 

From,

Bob

report size of disk usage BUT based off of type of storage used

$
0
0

So this is an interesting one. I need to report a vms disk usage in GB. ( thats the easy part) where I would appreciate help is....

 

lets say I have 50 vms, but out of those 50 vms, there are two types of storage: fast and slow disk I can allocate to my vms.

 

What I currently have is my datastores named in a way where I can query off of them as a way to do this..I hope. I name my datastores like:

ds7k-01 (slow disk)

or dsSSD-01(fast disk)

 

and lets say

vma is using ds7k-01 datastore

vmb is using dsSSD-01 datastore

 

 

I need to know how can I run my report and based off of a key word in the datastore name (keyword is 7k or SSD), and have it populate the correct field in my report.


the caveat, is below is how I created my report..so it would have to integrate into this stle of script...

 

the output of my report currently looks like this:

 

vm, cpu, memory

vma  2     6

 

I want it to look like this

 

vm, cpu, memory, slowdisk, fastdisk

vma  2      6           100          0   (better yet, if it is zero, do not put a 0 in the field.)

vmb   4    8              0          200

 

 

 

snipit of script....

 

 

$reportedvm= "" | Select-Object VM, CPU, Memory

$reportedvm.VirtualMachineName=$vm.name

$reportedvm.CPU=$vm.extensiondata.summary.config.numcpu

$reportedvm.Memory =$vm.Extensiondata.Summary.Config.memorySizeMB

...

...

...

 

 

sneddo
Correct Answer

 

Fast PowerOff & PowerOn certain VM's

$
0
0

We are doing  a test this weekend where I need to start/shutdown a certain amount of VM's It can be done by a simple script like :

Connect-VIServer vcenter1 -WarningAction:SilentlyContinue |Out-Null

$OTA = ipcsv D:\OTA.csv -Delimiter ";"

$AllVMs = $OTA | %{Get-VM $_.VM}

$AllVMs | Shutdown-VMGuest -Confirm:$false -WhatIf

Disconnect-VIServer vcenter1 -Confirm:$false -WarningAction:SilentlyContinue

 

But this takes about 10 minutes before the AllVMs array is build with about 64 targetted VM's. I have to little time to dive in to the get-view function and was wondering if this can be done faster anyhow. btw I need to start the machines also again, so I  want to use the same script but then with a start-vm. But if I can build the array a little faster it would be pretty helpfull so far

 

And yes, I added -whatif for testing of course

Transfering vmnic to Specific Uplink Port Group on Nexus 1000v

$
0
0

Hello all,  I need help tranfering a vmnic from an ESXi 5.5 to a specific Uplink Port Group on a Cisco Nexus 1000v.

 

Using PowerCLI 5.5, ESXi 5.5, vSphere 5.5

 

This is what I have:

 

 

 

$VMHost = ESXIHostname

$VDSwitch = XSW0010

 

 

#Get VMhost object data

$VMHostobj = Get-VMHost $VMHost

 

 

 

#Add to new DVSwitch

$VDSwitch = Get-VDSwitch $VDSwitch

$VDSwitch |  Add-VDSwitchVMHost -VMHost $VMHost -Confirm:$false

 

 

#Get physical adapter to move

$vmhostadapter = $VMhostObj | Get-VMHostNetworkAdapter -Physical -Name vmnic5

 

 

#Define Port Group Uplink on VDS

$PE_PROD_UPLINK = Get-VDPortGroup -Name PE_PROD_UPLINK -VDSwitch XSW0010

$ME_MGMT_UPLINK  = Get-VDPortGroup -Name ME_MANAGEMENT_UPLINK -VDSwitch XSW0010

 

 

# Add 1 physical adapter

Add-VDSwitchPhysicalNetworkAdapter -VirtualNicPortgroup "ME_MGMT_UPLINK" -DistributedSwitch $VDSwitch -VMHostPhysicalNic $vmhostadapter -Confirm:$false

 

 

 

I get the following error after the last line run's:

 

PowerCLI D:\Admin\Script> Add-VDSwitchPhysicalNetworkAdapter -VirtualNicPortgroup "ME_MGMT_UPLINK" -DistributedSwitch $VDSwitch -VMHostPhysicalNic $vmhostadapter -Confirm:$false

Add-VDSwitchPhysicalNetworkAdapter : No VirtualNics specified to be migrated to the specified portgroup(s)

At line:1 char:1

+ Add-VDSwitchPhysicalNetworkAdapter -VirtualNicPortgroup "ME_MGMT_UPLINK" -Distri ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Add-VDSwitchPhysicalNetworkAdapter], InvalidArgument

    + FullyQualifiedErrorId : VMware.VimAutomation.ViCore.Types.V1.ErrorHandling.InvalidArgument,VMware.VimAutomation.Vds.Commands.Cmdlets.AddVDSwitchPhysicalNetworkAdapter

 

 

 

If I run the following it runs fine but places the vmnic in the wrong port group

 

Add-VDSwitchPhysicalNetworkAdapter -DistributedSwitch $VDSwitch -VMHostPhysicalNic $vmhostadapter -Confirm:$false

 

 

 

Thanks for any help

Script Asking permission to stop service for each host

$
0
0

I have a script to start/stop SSH service on all hosts in each of my clusters.

 

When I run the script it is asking me to stop the service for each host, I would like for it to run without asking me. 

 

My execution policy is set to Unrestricted. 

 

I tried runing this directly from a .ps1 file and from PowerGUI.

 

Add-PSSnapin VMware.VimAutomation.Core

 

 

 

 

#Variables

$viserver = Read-Host "Please enter vCenter Server:"

 

 

Connect-VIServer $viserver

 

 

Get-Cluster | Get-VMHost | ForEach {Stop-VMHostService -HostService ($_ | Get-VMHostService | Where {$_.Key -eq “TSM-SSH”})}


Set-VM The vCenter Server is unable to decrypt passwords stored in the customization specification error

$
0
0

Getting this error running the PowerCLI code below

 

Environment

5.5 b

Using PowerCLI 5.5

Not using a custom certificate

 

1) Tried using clear text passwords in the script (not my preferred choice)

2) Tried retyping password in customization spec (join the domain and local administrator options)

3) Tried using Get-Credential as stored creds

4) I don't know how to put password in the XML as clear text (not my preferred choice) - Looking at this now.

 

#Load PowerCLI snap-in

function LoadSnapin{
  param($PSSnapinName)
  if (!(Get-PSSnapin | where {$_.Name   -eq $PSSnapinName})){
    Add-pssnapin -name $PSSnapinName
  }
}
LoadSnapin -PSSnapinName   "VMware.VimAutomation.Core"


#Create VM
$ParentVMName = "Parent2012r2VM"
$vCenterHostName = "vCenter"
$vCenterUserName="Domain\User"
$vCenterUserPassword="Password"
Connect-VIServer -Server "vCenter" -User $vCenterUserName -Password $vCenterUserPassword

#$cred = Get-Credential
#connect-viserver -Server "vCenter" -Credential

$cloneName = "Server1"
$sourceVM = Get-VM $ParentVMName | Get-View
$cloneFolder = $sourceVM.parent
$cloneSpec = new-object Vmware.Vim.VirtualMachineCloneSpec
$cloneSpec.Snapshot = $sourceVM.Snapshot.CurrentSnapshot
$cloneSpec.Location = new-object Vmware.Vim.VirtualMachineRelocateSpec
$cloneSpec.Location.DiskMoveType = [Vmware.Vim.VirtualMachineRelocateDiskMoveOptions]::createNewChildDiskBacking
$sourceVM.CloneVM_Task( $cloneFolder, $cloneName, $cloneSpec )


#Update temporary spec
[string]$Domain = "Domain"
[string]$DomainUserName = "user@domain"
[string]$DomainPassword = "password"
$Spec = Get-OSCustomizationSpec 'CustomSpec1' | New-OSCustomizationSpec -Name 'tmp01' -Type NonPersistent | Set-OSCustomizationSpec -Domain $Domain -DomainUsername $DomainUsername  -DomainPassword $DomainPassword
$Spec = Get-OSCustomizationNicMapping -Spec $Spec | Set-OSCustomizationNicMapping -IPmode UseStaticIP -IPAddress 'x.x.x.x' -SubnetMask x.x.x.x -DefaultGateway x.x.x.x -DNS 'x.x.x.x', 'x.x.x.x'
$Spec = Get-OSCustomizationSpec 'tmp01'


#Apply temporary spec
$VM = Get-VM "Server1"
Get-VM $VM | Get-NetworkAdapter | Set-NetworkAdapter -PortGroup 'PortGroup1' -confirm:$false | out-null
#Errors on this line
Get-VM $VM | Set-VM -OSCustomizationSpec $Spec -Confirm:$false | start-vm

Disconnect-VIServer -Server "vCenter" -Confirm:$false | out-null

the method is not supported in the api version 5.5

$
0
0

Hi im a new user to Powercli so forgive me if im doing something stupid.

 

I have used powershell a fair amount previously though.

 

after connecting to the vcentre Im trying to do some basic commands with powercli such a get-vm * or get-vm -name svr*

 

every command i try comes back with the method is not supported in the api version 5.5. i cant find any article on google relating to this issue.

 

some commands do work for example get-tag does return the available tags.

 

can some one help me resolve this please. i have tried multiple versions of powercli from 5.1 upto 5.5 r2.

 

even Powergui returns errors when i try that

Joining Domain with existing VM

$
0
0

Hello,

 

how can I join a domain with existing VMs? We have a couple of VMs which we want to join a domain via batch-file (PowerCLI). name etc. should stay as it is, only a domain join should be done.

 

Thanks in advance.

 

cu

Rainer Friedrich

send-mailmessage

$
0
0

in the body, how can I add text, but also add information gathered from cli.. (get-vm for example)

This is where unix scripting seems so much easier

 

example of what I would want in the body

"This is a test system I tested against"

get-vm myvm

 

is it an either or? one or the other only?

send-mailmessage -from "$smtpFrom" -to "$smtpTo" -subject "$messageSubject" -body "$body"  -smtpServer "$smtpserver"

Powercli for VM hardening 5.5

$
0
0

Can someone Please confirm below can be used for VM hardening :- (i got it from a post )

 

 

"Thanks for the tip, I was working on PowerCLI script the complies with disa stig and the hardening guide and this gave me the missing piece. Here it is in summary:

I created d:\vmware stig\stig_vm.txt file with the following input taken from DISA stig:"
isolation.bios.bbs.disable,TRUE
isolation.device.connectable.disable,TRUE
isolation.monitor.control.disable,TRUE
isolation.tools.diskShrink.disable,TRUE
isolation.tools.diskWiper.disable,TRUE
log.keepOld,10
log.rotateSize,100000
RemoteDisplay.maxConnections,1
tools.guestlib.enableHostInfo,FALSE
tools.setInfo.sizeLimit,1048576
vmci0.unrestricted,FALSE
isolation.tools.hgfsServerSet.disable,TRUE
isolation.device.edit.disable,TRUE
isolation.tools.autoInstall.disable,TRUE
isolation.tools.copy.disable,TRUE
isolation.tools.dnd.disable,FALSE
isolation.tools.setGUIOptions.enable,FALSE
isolation.tools.paste.disable,TRUE
isolation.tools.ghi.autologon.disable,TRUE
isolation.bios.bbs.disable,TRUE
isolation.tools.getCreds.disable,TRUE
isolation.tools.ghi.launchmenu.change,TRUE
isolation.tools.memSchedFakeSampleStats.disable,TRUE
isolation.tools.ghi.protocolhandler.info.disable,TRUE
isolation.ghi.host.shellAction.disable,TRUE
isolation.tools.dispTopoRequest.disable,TRUE
isolation.tools.trashFolderState.disable,TRUE
isolation.tools.ghi.trayicon.disable,TRUE
isolation.tools.unity.disable,TRUE
isolation.tools.unityInterlockOperation.disable,TRUE
isolation.tools.unity.push.update.disable,TRUE
isolation.tools.unity.taskbar.disable,TRUE
isolation.tools.unityActive.disable,TRUE
isolation.tools.unity.windowContents.disable,TRUE
isolation.tools.vmxDnDVersionGet.disable,TRUE
isolation.tools.guestDnDVersionSet.disable,TRUE
isolation.tools.vixMessage.disable,TRUE
tools.setinfo.sizeLimit,1048576

$stig_vm = Import-Csv ‘D:\VMWARE STIG\stig_vm.txt’ -Header Name,Value

::APPLY TO JUST MY_VM1
foreach ($line in $stig_vm) {
New-AdvancedSetting -Entity MY_VM1 -Name ($line.Name) -value ($line.value) -Force -Confirm:$false | Select Entity, Name, Value
}

::APPLY TO ALL VM
foreach ($line in $stig_vm) {
Get-VM | New-AdvancedSetting -Name ($line.Name) -value ($line.value) -Force -Confirm:$false | Select Entity, Name, Value | Export-Csv $output
}

 

 

 

I tried to follow the xls published by vmware , but i am not getting in eg,

 

# List the VMs and their current settings

Get-VM | Get-AdvancedSetting -Name  "isolation.tools.autoInstall.disable"| Select Entity, Name, Value

 

It gives me no o/p .. what does that mean ?

 

Please help

 

thanks

running powercli 5.5 path 1 on windows 2012 server

$
0
0

i get this error while running a script on windows 2012 server, it has, VMware vSphere PowerCLI 5.5 Release 2 Patch 1 build 1931983

 

During installation there were no error

 

The script has simple get vm cmdlets & some functions like export-xlsx etc

 

 

 

PowerCLI C:\powercli\scripts> .\xxx.ps1

New-Object : Retrieving the COM class factory for component with CLSID

{00000000-0000-0000-0000-000000000000} failed due to the following error:

80040154 Class not registered (Exception from HRESULT: 0x80040154

(REGDB_E_CLASSNOTREG)).

At C:\powercli\scripts\xxx.ps1:101 char:11

+     $xl = New-Object -ComObject Excel.Application

+           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : ResourceUnavailable: (:) [New-Object], COMExcept

   ion

    + FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Comman

   ds.NewObjectCommand

 

Property 'DisplayAlerts' cannot be found on this object; make sure it exists

and is settable.

 

 

but the same works well in windows 7

 

 

In this case the line 101 is :-

 

$xl = New-Object -ComObject Excel.Application

export-xlsx -Path `C:\Program Files (x86)\xxx` gives error

$
0
0

I am trying to do export to a location in C:\Program Files (x86)\ .. but the scripts errors out with below erroor

 

x86 : The term 'x86' is not recognized as the name of a cmdlet, function,

script file, or operable program. Check the spelling of the name, or if a path

was included, verify that the path is correct and try again.

At line:8 char:115

 

 

I tried  `C:\Program Files (x86)\xxx` ie with "`" but no luck

 

If i run that manually works well, but in a script the path error , can someone Please help


Script for datastore content

$
0
0

Hi,

 

I am new in the Vmware world of scripting.

I am using powercli and working true some example scripts to find my way around.

Currently i am creating an inventory of the existing vmware infrastructure.

I have a list of all VM's and their datastore, but i need also a datastore content.

Like:

a list of all datastores in a datacenter.

Get all content of the datastore (folders, vmdk files, iso files, other files)

Get a list of all folders / files with VMservers still known in the inventory.

 

The goal is to know if there are files/VMservers on the datastore that are no longer in use, and to check if we have duplicate files in other datastores

 

Thanks in advance for any assistence.

 

Best regards

Dany

HBA Queue depth

$
0
0

Hi team,

 

I would like to find out HBA/Device/LUN queue depth of ESX host using Power CLI and firmware details of HBA too.

Understand we can find this information using ESXTOP, which is more of a manual way of doing it. Please refer below article for what I am looking for.

Plus I want to avoid any way of scripting using plink.exe to run the commands as root. Basically I want to pull this information by connecting to vcenter from powercli.

 

http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1027901

 

Any help is appreciated.

 

Regards

Heera

Remove detached device using powershell scripts.

$
0
0

$E01 = get-esxcli -vmhost test01

$ED01 = $e01.storage.core.device.detached.list() # I have 10 devices here

$e01.storage.core.device.detached.remove($ED01) error as follows

 

PowerCLI C:\scripts> $e01.storage.core.device.detached.remove($ed01)
A specified parameter was not correct.
method
At line:1 char:41
+ $e01.storage.core.device.detached.remove <<<< ($ed01)
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : MethodInvocationException

how to loop the list of devices in detached list that needs to be removed,

Hot to set vm's CpuFeatureMask ?

$
0
0

I guess I've to use something like:

 

$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec

 

 

$vmConfigSpec.CpuFeatureMask = New-Object VMware.Vim.VirtualMachineCpuIdInfoSpec

 

 

and then use the ReconfigVM_Task

 

 

But I get confused with the type VirtualMachineCpuIdInfoSpec, when I read CpuFeatureMask of an existing VM, it is an array of 10 elements, while the New-Object has only one element and not the same properties..?

 

 

 

Thanks for help.

vCenter 5.1 and SSO Failover - Who needs heartbeat?

$
0
0

So for those of us who don't want to drop the 10k per license on Heartbeat, here is a work around. While it is not as flashy, it is a free option. Also, while the process as a whole is not supported, the individual pieces are. Here are the pre-reqs for this to work:

 

1. 2 servers setup as Primary SSO and Web Client (they should not know about each other)

2. vCenter and Inventory Services on same VM.

3. You are cloning your vCenter Server VM and it remains powered off until there is a BCP event (scriptable)

4. You have either a CNAME, F5, or some other way to repoint your vCenter IP.

5. 7zip needs to be installed on your vCenter Server (can be replaced with some other unzip commandline)

6. Needs to be run from an x86 PowerCLI session. (Invoke-VMScript)

7. Your vCenter Infrastructure servers are not running in the vCenter you are failing over. (working on a version that this is not required)

 

Function Set-WinVMIP ($VM, $IP, $SNM, $GW)

#host root creds
$rcred = new-object -typename System.Management.Automation.PSCredential -argumentlist "root",$pass
#vm guest creds
$gcred = new-object -typename System.Management.Automation.PSCredential -argumentlist "DOMAIN\User",$pass

   $netsh1 = "c:\windows\system32\netsh.exe interface ip set address ""Local Area Connection"" static $IP $SNM $GW 1"
   $netsh2 = "c:\windows\system32\netsh.exe interface ip set dns ""Local Area Connection"" static $DNS1"
   $netsh3 = "c:\windows\system32\netsh.exe interface ip add dns ""Local Area Connection"" $DNS2 index=2"
   $netsh4 = "c:\windows\system32\netsh.exe interface ip set wins ""Local Area Connection"" static $WINS1"
   $netsh5 = "c:\windows\system32\netsh.exe interface ip add wins ""Local Area Connection"" $WINS2"
  
   Write-Host "Setting IP address for $VM..." 
   Invoke-VMScript -VM $VM -HostCredential $rcred -GuestCredential $gcred -ScriptText $netsh1 -ScriptType Bat -Confirm:$false
   Invoke-VMScript -VM $VM -HostCredential $rcred -GuestCredential $gcred -ScriptText $netsh2 -ScriptType Bat -Confirm:$false
   Invoke-VMScript -VM $VM -HostCredential $rcred -GuestCredential $gcred -ScriptText $netsh3 -ScriptType Bat -Confirm:$false
   Invoke-VMScript -VM $VM -HostCredential $rcred -GuestCredential $gcred -ScriptText $netsh4 -ScriptType Bat -Confirm:$false
   Invoke-VMScript -VM $VM -HostCredential $rcred -GuestCredential $gcred -ScriptText $netsh5 -ScriptType Bat -Confirm:$false
   Write-Host "Setting IP address completed."

Function RepointVC($VM, $lookup)
{
#host root creds
$rcred = new-object -typename System.Management.Automation.PSCredential -argumentlist "root",$pass
#vm guest creds
$gcred = new-object -typename System.Management.Automation.PSCredential -argumentlist "DOMAIN\User",$pass

$netsh1 = '"PathTo\VMware\Infrastructure\Inventory Service\scripts\is-change-sso.bat" ' + $lookup + ' admin@System-Domain "MyAdminPassword"'
$netsh2 = "net stop vimQueryService"
$netsh3 = "net start vimQueryService"
$netsh4 = '"PathTo\7z.exe" x "PathTo\VMware\Infrastructure\VirtualCenter Server\ssoregtool\sso_svccfg.zip" -oc:\temp\sso_svccfg -y'
$netsh5 = 'C:\temp\sso_svccfg\repoint.cmd configure-vc --lookup-server ' + $lookup + ' --user admin@system-domain --password "MyAdminPassword" --openssl-path "PathTo\VMware\Infrastructure\Inventory Service\bin"'
$netsh6 = "rd c:\temp\sso_svccfg /S /Q"

Write-Host "Repointing vCenter SSO" 
Invoke-VMScript -VM $VM -HostCredential $rcred -GuestCredential $gcred -ScriptText $netsh1 -ScriptType Bat -Confirm:$false
Invoke-VMScript -VM $VM -HostCredential $rcred -GuestCredential $gcred -ScriptText $netsh2 -ScriptType Bat -Confirm:$false
Invoke-VMScript -VM $VM -HostCredential $rcred -GuestCredential $gcred -ScriptText $netsh3 -ScriptType Bat -Confirm:$false
Invoke-VMScript -VM $VM -HostCredential $rcred -GuestCredential $gcred -ScriptText $netsh4 -ScriptType Bat -Confirm:$false
Invoke-VMScript -VM $VM -HostCredential $rcred -GuestCredential $gcred -ScriptText $netsh5 -ScriptType Bat -Confirm:$false
Invoke-VMScript -VM $VM -HostCredential $rcred -GuestCredential $gcred -ScriptText $netsh6 -ScriptType Bat -Confirm:$false
}

$File = "PathTo\failover.txt"

$targ = "MyVCVM"

$str = (Get-Date)
$log = "`n"
$log += $str
$log += " MyVCName"

Connect-VIServer "MyVC"

$livevc = Get-VM -Name $targ | where {$_.PowerState -eq "PoweredOn"}
$bcpvc = Get-VM -Name $targ | where {$_.PowerState -eq "PoweredOff"}

$liveclus = Get-Cluster -VM $livevc
$bcpclus = Get-Cluster -VM $bcpvc

if($bcpclus.Name -eq "MyProdCluster")
{
$IP = "192.168.1.2"
$SNM = "255.255.255.0"
$GW = "192.168.1.1"
$DNS1 = "192.168.1.1"
$DNS2 = "192.168.2.1"
$WINS1 = "192.168.1.1"
$WINS2 = "192.168.2.1"
$lookup = "https://MyProdSOServerFQDN:7444/lookupservice/sdk"
$SSO = "MyProdSSOServer"
}   

if($bcpclus.Name -eq "MyBCPCluster")
{
$IP = "192.168.2.2"
$SNM = "255.255.255.0"
$GW = "192.168.2.1"
$DNS1 = "192.168.2.1"
$DNS2 = "192.168.1.1"
$WINS1 = "192.168.2.1"
$WINS2 = "192.168.1.1"
$lookup = "https://MyBCPSOServerFQDN:7444/lookupservice/sdk"
$SSO = "MyBCPSSOServer"
}   

try
{
Write-Host -ForegroundColor DarkGreen "Powering On VM"
Stop-VM -VM $livevc -Confirm:$false | Out-Null
Start-VM -VM $bcpvc -Confirm:$false | Out-Null
sleep 180
}
catch [System.Exception]
{
$log += "Failed Power On VM`n"
}

 

$bcpvc = Get-VM -Name $targ | where {$_.PowerState -eq "PoweredOn"}

 

$ServiceObj = Get-Service -Name "vspherewebclientsvc" -ComputerName $SSO -ErrorAction Continue
Stop-Service -InputObj $ServiceObj -erroraction Continue

 

try
{
Write-Host -ForegroundColor DarkGreen "Setting IP on Target"
Set-WinVMIP $bcpvc $IP $SNM $GW
RepointVC $bcpvc $lookup
sleep 30
}
catch [System.Exception]
{
$log += "Failed IP Change`n"
}

 

Disconnect-VIServer -Server * -Confirm:$false

 

$ServiceObj = Get-Service -Name "ssotomcat" -ComputerName $SSO -ErrorAction Continue
Restart-Service -InputObj $ServiceObj -erroraction Continue

 

$ServiceObj = Get-Service -Name "vpxd" -ComputerName $targ -ErrorAction Continue
Restart-Service -InputObj $ServiceObj -erroraction Continue -Force

 

$ServiceObj = Get-Service -Name "vctomcat" -ComputerName $targ -ErrorAction Continue
Start-Service -InputObj $ServiceObj -erroraction Continue

 

$ServiceObj = Get-Service -Name "vspherewebclientsvc" -ComputerName $SSO -ErrorAction Continue
Restart-Service -InputObj $ServiceObj -erroraction Continue

Viewing all 14549 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>