Quantcast
Channel: VMware Communities : All Content - VMware PowerCLI
Viewing all 16717 articles
Browse latest View live

New/Remove-VM: Operation is not valid due to the current state of the object.

$
0
0

I'm working on a script to mass deploy VM's from a CSV-file (thanks all who've helped in my previous post/s). I have entered data for 2 servers in the CSV-file. The script can deploy from either a template or blank (without OS) with only the data of the CSV-file. This script was working fine until I suddenly, without any changes to the script mind you, recieved this error:

 

PowerCLI C:\Temp\> .\NewVM-1.1.ps1

New-VM : 2013-04-18 12:51:49    New-VM        Operation is not valid due to the current state of the object.
At C:\Temp\NewVM-1.1.ps1:55 char:9
+         New-VM -Template $Template `
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [New-VM], VimException
    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomatio
   n.ViCore.Cmdlets.Commands.NewVM
New-VM : 2013-04-18 12:51:53    New-VM        Operation is not valid due to the current state of the object.
At C:\Temp\NewVM-1.1.ps1:55 char:9
+         New-VM -Template $Template `
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [New-VM], VimException
    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomatio
   n.ViCore.Cmdlets.Commands.NewVM

 

As you see above this is when I specified a template. At the moment this doesn't happen when I don't use template, but it did that too before.

PowerCLI C:\Temp\> .\CleanUp.ps1
Remove-VM : 2013-04-18 12:51:59    Remove-VM        Operation is not valid due to the current state of the object.
At C:\Temp\CleanUp.ps1:2 char:5
+     Remove-VM $row.Name -DeletePermanently -Confirm:$false
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Remove-VM], VimException
    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomatio
   n.ViCore.Cmdlets.Commands.RemoveVM
Remove-VM : 2013-04-18 12:52:00    Remove-VM        Operation is not valid due to the current state of the object.
At C:\Temp\CleanUp.ps1:2 char:5
+     Remove-VM $row.Name -DeletePermanently -Confirm:$false
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Remove-VM], VimException
    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomatio
   n.ViCore.Cmdlets.Commands.RemoveVM

 

 

CleanUp-script removes the VM's created. At the moment this happens even if the VM's were created without error.


Even though I recieve the error the VM's are created/removed, but the rest of the script won't continue because of it (such as add extra hard drives and annotations). Also, it isn't every time that I get the error, sometimes both VM's are create, sometimes 1 of the two and sometimes none.


Some information that might help regarding our test environment that I run the script in:

Not running Power GUI (yes, i've read http://communities.vmware.com/message/1702069).

 

PowerCLI Version:

PowerCLI C:\Temp\> Get-PowerCLIVersion

   VMware vSphere PowerCLI 5.1 Release 2 build 1012425


PowerShell Version:

PS C:\Users> get-host

Name             : ConsoleHost

Version          : 3.0

 

As stated in http://communities.vmware.com/message/2146831, previously there wasn't support for Powershell 3, but from what I understand of http://blogs.vmware.com/vipowershell/2013/02/powercli-5-1-release-2-now-available.html that shouldn't be a problem anymore.


My question is therefor: What reasons are therewhich might cause this error?


Linux - vSphere 6 POWER CLI

$
0
0

I am trying to construct a deployment set of scripts.  The environment is bringing in OEM systems pre-loaded with base vSphere but need script to automate a bunch of steps for vSwitch creation, MTU etc....

 

 

As such I built a deployment system for these steps using "VMWare POWERCLI"

 

I built this initially on Windows, but want to deploy this en-mass, so want to wrap this up as a "deployment system" for sites and to avoid License issues, want to convert it to work on CentOS.

 

 

So I figured it would be easy,  develop on Windows then move scripts over to CentOS, launch power shell from within bash...   call on pre-built VMWare POWERCLI scripts....

 

HMmm.

 

Linux

Step 1: Download and Install

 

From Linux system (Example CentOS 6) install package

[root@vsmgr00 ~]# cp /media/labfiles/Software/vmware/6/VMware-PowerCLI-6.3.0-3639347.oss.tgz /tmp/

[root@vsmgr00 ~]# cd /tmp/

[root@vsmgr00 tmp]# tar -zxvf VMware-PowerCLI-6.3.0-3639347.oss.tgz

 

 

[root@vsmgr00 tmp]# cd vmware-vsphere-cli-distrib

[root@vsmgr00 vmware-vsphere-cli-distrib]# ls

apps  bin doc  etc  FILES lib  Makefile.PL  man resources  vmware-install.pl

[root@ibmvsmgr00 vmware-vsphere-cli-distrib]# ./vmware-install.pl

Installing vSphere CLI 6.0.0 build-2503617 for Linux.

 

You must read and accept the vSphere CLI End User License Agreement to

  1. continue.

Press enter to display it.

 

 

terms will continue to be valid and enforceable to the fullest extent

permitted

by law.

 

 

 

 

Do you accept? (yes/no)  yes

 

Thank you.

 

This vSphere CLI installer includes precompiled Perl modules for RHEL.

Answering yes will install the precompiled modules, and answering no will

install from CPAN.

Do you want to install precompiled Perl modules for RHEL?

[yes]

 

In which directory do you want to install the executable files?

[/usr/bin]

 

Please wait while copying vSphere CLI files...

The installation of vSphere CLI 6.0.0 build-2503617 for Linux completed

  1. You can decide to remove this software from your system at any

time by invoking the following command:

"/usr/bin/vmware-uninstall-vSphere-CLI.pl".

 

This installer has successfully installed both vSphere CLI and the vSphere SDK for Perl.

 

The following Perl modules were found on the system but may be too old to work with vSphere CLI:

 

MIME::Base64 3.14 or newer

version 0.78 or newer

 

Enjoy,

 

--the VMware team

 

[root@vsmgr00 vmware-vsphere-cli-distrib]#

 

 

Launch PowerCLI shell

 

[root@ibmvsmgr00 tmp]# cd /usr/bin/

[root@ibmvsmgr00 bin]# ls -alh vmw*

-r-xr-xr-x. 1 root root  59K Jul  5 14:25 vmware-cmd

-rwxr-xr-x. 1 root root 404K Feb 26 11:22 vmware-config-tools.pl

lrwxrwxrwx. 1 root root   37 May 27 08:29 vmware-guestproxycerttool -> /usr/lib/vmware-tools/bin64/appLoader

lrwxrwxrwx. 1 root root   37 May 27 08:29 vmware-hgfsclient -> /usr/lib/vmware-tools/bin64/appLoader

lrwxrwxrwx. 1 root root   37 May 27 08:29 vmware-toolbox-cmd -> /usr/lib/vmware-tools/bin64/appLoader

-rwxr-xr-x. 1 root root 195K Feb 26 11:22 vmware-uninstall-tools.pl

-r-xr-xr-x. 1 root root 125K Jul  5 14:25 vmware-uninstall-vSphere-CLI.pl

lrwxrwxrwx. 1 root root   52 May 27 08:29 vmware-user -> /usr/lib/vmware-tools/bin64/vmware-user-suid-wrapper

lrwxrwxrwx. 1 root root   48 May 27 08:29 vmware-xdg-detect-de -> /usr/lib/vmware-tools/bin32/vmware-xdg-detect-de

lrwxrwxrwx. 1 root root   43 May 27 08:29 vmware-xferlogs -> /usr/lib/vmware-tools/bin64/vmware-xferlogs

[root@ibmvsmgr00 bin]# ./vmware-cmd

Can't locate Compress/Raw/Zlib.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /usr/lib64/perl5/Archive/Zip.pm line 11.

BEGIN failed--compilation aborted at /usr/lib64/perl5/Archive/Zip.pm line 11.

Compilation failed in require at /usr/share/perl5/VMware/VIExt.pm line 11.

BEGIN failed--compilation aborted at /usr/share/perl5/VMware/VIExt.pm line 11.

Compilation failed in require at ./vmware-cmd line 10.

BEGIN failed--compilation aborted at ./vmware-cmd line 10.

[root@ibmvsmgr00 bin]#  hmmm....

 

[root@ibmvsmgr00 bin]# ./vmware-toolbox-cmd

./vmware-toolbox-cmd: Missing command

Try './vmware-toolbox-cmd help' for more information.

[root@ibmvsmgr00 bin]#

 


 

 

Within Windows you just launch it and it works

 

Windows

 

 

Launch CLI Power Shell

 

WindowsVMWarePOWERCLI.png

 

Connect to vCenter. Example:  vcenter.acme.com

"Connect-CIServer vcenter.acme.com"

Connect—CISeruer ucenter.acme.com Specify Credential Please specify vcenter.acme.com credenbal Password: " height="474" width="705">

 

 

Question:

1) What is the proper way to get Linux PowerCLI shell to launch?

 

 

2) Is the failure I am seeing due to CentOS Perl library, if so, why did it not check during install, and what is expected version?

Change vcloud template to Goldmaster

$
0
0

Im building a script that creates a vApp template from an existing vApp i vCloud.

The problem is that im not able to change the attribute IsGoldMaster on the existing vApp template created.

This is what im using to create the template:

 

$myVApp = Get-CIVApp vAppname

#Create template from vApp

$myVApp | New-CIVAppTemplate -Name $templatename -OrgVdc $vcloudorg -Catalog $Catalog -Description 'UpdatedTemplate' -CustomizeOnInstantiate:$true

 

I see there is a way to add the -GoldMaster switch on the Import-CIVappTemplate but not on New-CIVappTemplate command. Is it possible to change IsGoldMaster attribute on existing template?
Or do anyone have a better way to do this?

 

Regards,

Linus

Licensing a vCenter 6 instance via PowerCLI 6

$
0
0

When installing vCenter 5.5 on Windows I was able to supply the license key as a parameter to license the vCenter instance at install time like so:

 

VMware-vcserver.exe /q /s /w /L1033 /v" /qr LICENSEKEY=xxxxx-xxxxx-xxxxx-xxxxx-xxxxx DB_SERVER_TYPE=Bundled FORMAT_DB=1 SSO_ADMIN_PASSWORD=$SSO_ADM_PASS LS_URL=$LSURL IS_URL=$ISURL VC_ADMIN_USER=Administrators VC_ADMIN_IS_GROUP_VPXD_TXT=True /L*v c:\temp\vcinstall.log"

 

I tried with the vCenter 6 installer and providing the license key as part of the install parameters did not work.

 

So I have read various articles and was able to add the license to the vCenter's License Manager. It now shows up correctly.

 

But this command does not work anymore:

 

$vCenterLicenseAssignmentManager.UpdateAssignedLicense($vCenterUuid, $vCenterLicenseKey, $vCenterDisplayName)

 

UpdateAssignedLicense has been deprecated.


I tried this (after finding the V1 hint until the patch for this is released):


$LicenseDataManager = Get-LicenseDataManager -Server $VIServer

$licenseData = New-Object Vmware.VimAutomation.License.Types.V1.LicenseData

$licenseKeyEntry = New-Object Vmware.VimAutomation.License.Types.V1.LicenseKeyEntry

$licenseKeyEntry.TypeId = "vmware-vsphere"

$licenseKeyEntry.LicenseKey = $vCenter6LicenseKey

$licenseData.LicenseKeys += $licenseKeyEntry

$licenseDataManager.UpdateAssociatedLicenseData($vCenterUuid, $licenseData)

 

But this fails as the TypeID of the license does not seem to be right. Where can I get the correct TypeID for a vCenter license? I guess the TypeId I am using identifies the license as an ESXi license?

Am I one the right track otherwise? Is there an easier way of doing this?

Need to get distributed switch information of a host

$
0
0

Hi all,

I would like to fetch the distributed switch information of a host.

With the below script am able to get the switch name, network cards added to this dvswitch and its status.

$report= @()
foreach($swin (Get-VirtualSwitch-Distributed)){
   
$uuid=$sw.ExtensionData.Summary.Uuid
   
$sw.ExtensionData.Config.Host | %{
       
$portStates=$sw.ExtensionData.FetchDVPorts($null)
       
$esx=Get-View$_.Config.Host
       
$netSys=Get-View$esx.ConfigManager.NetworkSystem
       
$netSys.NetworkConfig.ProxySwitch | where {$_.Uuid -eq$uuid} | %{
           
foreach($pnicSpecin$_.Spec.Backing.PnicSpec){
               
$row="" | Select Host,dvSwitch,PNic,PortLinkUp
               
$row.Host =$esx.Name
               
$row.dvSwitch =$sw.Name
               
$row.PNic =$pnicSPec.PnicDevice
               
$row.PortLinkUp = ($portStates | where{$_.Key -eq$pnicSPec.UplinkPortKey}).State.RunTimeInfo.LinkUp
               
$report+=$row
            }
        }
    }
}

$report


But i would like to get the physical switch information(name of the physical switch and the port information of each vmnic connected to this host. Please help to fetch the same.

Note:

CDP information is enabled.

Error: ChangeSID property of the customization specification should be set to TRUE...

$
0
0

Hi,

 

I develop an orchestrated process for new virtual server provisioning. Environment is vCenter 5.5, PowerCLI 6.3.0.0, PowerShell 4.0. Key element is vCenter template with Windows Server 2012 R2.

 

To finalize the operating system we use OS Customization Specification file which is built “on the fly” before creating new VM.

 

Basically there is two scenarios. First scenario is when we let the OS Customization Specification process to perform sysprep or in vCenter terminology ChangeSID. This one work as expected.

 

The second scenario is when the operating system in template is already sysprep-ed. In this case we do not need sysprep again, right. So, we create OS Customization Specification file using

 

New-OSCustomizationSpec cmdlet and omit -ChangeSid parameter. Cmdlet reference vSphere PowerCLI Reference (63R1) also shows  that -ChangeSid is not required parameter.

 

But when I try to create new VM with New-VM cmdlet, and specify above OS Customization Specification file (which doesn’t include parameter -ChangeSid), I get the following error:

 

New-VM : 6.7.2016 16:01:25    New-VM        ChangeSID property of the customization specification should be set to TRUE because the guest OS 'Microsoft Windows Server 2012 (64-bit) ' doesn't support FALSE value.

 

It’s not matter which operating system version I select under Settings|Options|General Options|Guest Operating System|Version settings.

 

I understand error massage but it’s strange in two aspects. First is that the parameter is not required (look cmdlet reference link above) and other is that scenario in which operating system is already sysprep-ed and is completely legitimate.

 

Any help, hints or trick how to solve that, will be appreciated.

 

Thanks in advanced.

 

Regards,

  Ivan

A way to check if the vmdk exists with powercli

$
0
0

Hi

 

We had an issue with a HPOO flow run in our enterprise. It was looking to delete phantom vmdk but it ended up deleting vmdk descriptor files. We found them by looking to see if capacitygb equaled 0. We are fixing the issue by fixing the descriptor files but came across a virtual server with normal capacity but the vmdk's did not exist.

 

Now I am worried how many more like this exist. Appreciate any thoughts on a script or one liner to see if the vmdk files exist for a flat file

 

thanks

Host Server power Management and processor options to be fetched

$
0
0

Hi all,

Our ESXi host runs on HP hardware.

My requirement is to fetch the below.

 

Power Management Options

Processor Options Enabled

Boot Order Options

 

I could see HP cmdlets in HP website for windows operating system but unable to find for ESXi hosts..

IS there a way to fetch these BIOS level information from ESXi host / from the bios itself.

Please help.


Fetch host hardware information

$
0
0

Hi all,

I would like to fetch the information available from health status of ESXi host .

Configuration --> Hardware --> Health Status

 

Need to fetch hard disk size, raid level of local harddisk, BMC firmware version etc.

 

Please advice how to fetch the same using powercli.

Powercli script to perform vCenter 6 snasphots from csv

$
0
0

Hello,

We have a group of servers that we want to perform operating system patches. We would like to first take a snapshot of these servers. Does anyone have a powercli script in which it will read a csv of the server names and go out and perform a snapshot and give the snapshot a name specified in the script? We are using vCenter 6. Thanks.

Scan-Inventory -> The term 'Test-Compliance' is not recognized as the name of a cmdlet

$
0
0

Hi,

 

not sure what is going wrong at the moment, but I've installed VUM powercli package and I did some testing yesterday. Today Scan-Inentory and other VUM powercli commands fail with error "Test-Compliance' is not recognized as the name of a cmdlet..."

 

But as far as I can see the VUM powercli snapin/module is installed and loaded.

 

 

Scan-Inventory -Entity xxxx

Scan-Inventory : The term 'Test-Compliance' 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:1 char:1

+ Scan-Inventory -Entity xxxxx

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

    + CategoryInfo          : ObjectNotFound: (Test-Compliance:String) [], CommandNotFoundException

    + FullyQualifiedErrorId : CommandNotFoundException

 

 

Add-PSSnapin VMware.VumAutomation

Add-PSSnapin : Cannot add Windows PowerShell snap-in VMware.VumAutomation because it is already added. Verify the name of the snap-in, and then try again.

At line:1 char:1

+ Add-PSSnapin VMware.VumAutomation

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

    + CategoryInfo          : InvalidArgument: (VMware.VumAutomation:String) [Add-PSSnapin], PSArgumentException

    + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand

 

 

> Import-Module VMware.VumAutomation -Verbose                                                                                                                                                              

VERBOSE: Loading module from path 'C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Modules\VMware.VumAutomation\VMware.VumAutomation.psd1'.

VERBOSE: Loading 'Assembly' from path 'C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Modules\VMware.VumAutomation\IntegritySoapService40.dll'.

VERBOSE: Loading 'Assembly' from path 'C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Modules\VMware.VumAutomation\IntegritySoapService40.XmlSerializers.dll'.

VERBOSE: Loading 'Assembly' from path 'C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Modules\VMware.VumAutomation\VMware.VumAutomation.Client40.dll'.

VERBOSE: Loading 'Assembly' from path 'C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\VMware.VumAutomation.dll'.

VERBOSE: Loading 'Assembly' from path 'C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\VMware.VumAutomation.Types.dll'.

VERBOSE: Loading 'FormatsToProcess' from path 'C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Modules\VMware.VumAutomation\VMware.VumAutomation.Format.ps1xml'.

VERBOSE: Loading module from path 'C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Modules\VMware.VumAutomation\Initialize-VMware_VumAutomation.ps1'.

VERBOSE: Dot-sourcing the script file 'C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Modules\VMware.VumAutomation\Initialize-VMware_VumAutomation.ps1'.

VERBOSE: Loading module from path 'C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Modules\VMware.VumAutomation\VMware.VumAutomation.ps1'.

VERBOSE: Dot-sourcing the script file 'C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Modules\VMware.VumAutomation\VMware.VumAutomation.ps1'.

VERBOSE: Loading module from path 'C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Modules\VMware.VumAutomation\VMware.VumAutomation.dll'.

VERBOSE: Exporting cmdlet 'Attach-Baseline'.

VERBOSE: Exporting cmdlet 'Get-Baseline'.

VERBOSE: Exporting cmdlet 'Detach-Baseline'.

VERBOSE: Exporting cmdlet 'Download-Patch'.

VERBOSE: Exporting cmdlet 'Get-Compliance'.

VERBOSE: Exporting cmdlet 'Get-Patch'.

VERBOSE: Exporting cmdlet 'Get-PatchBaseline'.

VERBOSE: Exporting cmdlet 'New-PatchBaseline'.

VERBOSE: Exporting cmdlet 'Remove-Baseline'.

VERBOSE: Exporting cmdlet 'Set-PatchBaseline'.

VERBOSE: Exporting cmdlet 'Remediate-Inventory'.

VERBOSE: Exporting cmdlet 'Scan-Inventory'.

VERBOSE: Exporting cmdlet 'Stage-Patch'.

WARNING: The names of some imported commands from the module 'VMware.VumAutomation' include unapproved verbs that might make them less discoverable. To find the commands with unapproved verbs, run the Import-Module command again with the Verbose parameter. For a list of approved verbs, type Get-Verb.

VERBOSE: The 'Attach-Baseline' command in the VMware.VumAutomation' module was imported, but because its name does not include an approved verb, it might be difficult to find. The suggested alternative verbs are "Add, Debug".

VERBOSE: Importing cmdlet 'Attach-Baseline'.

VERBOSE: The 'Detach-Baseline' command in the VMware.VumAutomation' module was imported, but because its name does not include an approved verb, it might be difficult to find. The suggested alternative verbs are "Dismount, Remove".

VERBOSE: Importing cmdlet 'Detach-Baseline'.

VERBOSE: The 'Download-Patch' command in the VMware.VumAutomation' module was imported, but because its name does not include an approved verb, it might be difficult to find. For a list of approved verbs, type Get-Verb.

VERBOSE: Importing cmdlet 'Download-Patch'.

VERBOSE: Importing cmdlet 'Get-Baseline'.

VERBOSE: Importing cmdlet 'Get-Compliance'.

VERBOSE: Importing cmdlet 'Get-Patch'.

VERBOSE: Importing cmdlet 'Get-PatchBaseline'.

VERBOSE: Importing cmdlet 'New-PatchBaseline'.

VERBOSE: The 'Remediate-Inventory' command in the VMware.VumAutomation' module was imported, but because its name does not include an approved verb, it might be difficult to find. For a list of approved verbs, type Get-Verb.

VERBOSE: Importing cmdlet 'Remediate-Inventory'.

VERBOSE: Importing cmdlet 'Remove-Baseline'.

VERBOSE: The 'Scan-Inventory' command in the VMware.VumAutomation' module was imported, but because its name does not include an approved verb, it might be difficult to find. For a list of approved verbs, type Get-Verb.

VERBOSE: Importing cmdlet 'Scan-Inventory'.

VERBOSE: Importing cmdlet 'Set-PatchBaseline'.

VERBOSE: The 'Stage-Patch' command in the VMware.VumAutomation' module was imported, but because its name does not include an approved verb, it might be difficult to find. For a list of approved verbs, type Get-Verb.

VERBOSE: Importing cmdlet 'Stage-Patch'.

adding serial port

$
0
0

I'm trying to add a serial port to a vm to point to the ESXI hosts physical serial port. I have to repeat this about a hundred times, so looking to script this. I can find scripts for doing this with other types of serial ports, but been unable to adapt this to a physical serial port mapped through.

Thanks

How do I move a .vmdk file from a data store directly to a Rest interface?

$
0
0

Must the Windows machine with PowerCLI be an intermediary?  Or is there a way to bypass the Windows server with PowerCLI and transfer the .vmdk directly from the datastore on the ESX server to the remote server with a Rest interface?

 

Is there an alternative to copy-datastoreitem where the destination can be a URL?

 

I am using Invoke-RestMethod -Uri "http://destination.com" -InFile C:\temp\sourcefile.vmdk" to get VMDK files to the REST interface.  The source for Invoke-RestMethod, as far as my knowledge goes, must be a file or a variable in memory.  I'd rather not write the VMDK to this Windows server with PowerCLI.  Variables in memory must be smaller than the size of these VMDK files due to RAM constraints.  Is there network buffer or stream that I can set up?

 

Is there a compound command that I can write to use copy-datastoreitem to get the file from the data store (on the ESX server) to go directly to the Rest interface?  If there is a fake file, or file representation of an invocation of a PowerShell command, that could help me join these two functions and keep the VMDK file off the hard disk and out or memory on the server that I am using PowerCLI on.

 

I tried this command:

$s = Get-Datastore Datastore1

 

I put this line as the InFile argument of my Invoke-RestMethod:  $s.ExtensionData.info.url

But running the command I get an error.

 

I can use Get-Datastore datastore1 | get-vm | get-harddisk

# The above will result in showing acme.vmdk with a capacity of 20 GB.  But when I save it (with copy-datastoreitem -item <source> <item>), acme.vmdk is 1 KB.  How can I copy it with thick provisioning?

 

For performance reasons, I'd rather not write the VMDK to the local server I have with PowerCLI.

PowerCLI transfers a file but the copied file size is way too small. What is wrong?

$
0
0

I am using PowerCLI version 6 on a Windows server with 20 GB of free space. I am trying to use copy-datastoreitem with PowerCLI. It seems to work to transfer a .vmdk file from an ESXi datastore to the Windows server that has PowerCLI. There are no error messages, but there is one problem. The .VMDK file takes up 5 GB of space in the datastore. The vSphere GUI reflects this. The copy file, on the Windows server after the PowerCLI command runs, is only 1 KB. Clearly the copy did not work correctly.

 

Is there another command besides the copy-datastoreitem command that works more effectively?

 

What would cause the file sizes to be so different? Using other PowerCLI commands, I found the 5 GB file (the source file) has the capacity for 35 GB of storage space as a VM. It is a working, non-corrupt file. The copy is not. But my PowerCLI commands have no errors. There is evidence that they work except for a huge difference in the size of the copied file. The problem is 100% reproducible.

New-SCSIController, issue adding new SCSI when connected to ESX or Vcenter

$
0
0

Hi All,

 

I'm having a bit of an issue figuring out how to add a second scsi controller to a VM. The VM itself has 7 RDM, which I try to connect to second SCSI. The idea is to share these RDM with a second VM later on, but can not yet get to that point. This is all being done within a .ps1 file, however, at one point I was able to get it to work directly on the terminal. Unfortunately I didn't really note down which connection I had. My steps are as follows:

 

- Log in to ESX server where VM will be created

- Create basic VM with single disk

- Add 7 additional RDM

- Use the following to create new SCSI controller:

   $scsi = New-ScsiController -HardDisk $shared_rdm -BusSharingMode physical -Type VirtualLsiLogic    # Where $shared_rdm is the 7 rdm from above

 

As soon as it hits this point, I get the following error:

"The operation for the entity "my_vm" failed with the following message: "Access to resource settings on the host is restricted to the server that is managing it: <ip of the vcenter>""

So what that was telling me is that my connection needs to be with the vcenter for this to work, so after adding disks and before creating new scsi, i add the following steps:

 

Disconnect-VIServer -server *

Connect-VIServer -server <ip_of_vcenter>     # Note I also tried with the FQDN

 

So now, when running, I get the following error:

"The server connection root@esx_fqdn is required by the current operation. The connection does not exist, possibly because it was actively closed or timed out."

So from what I see, if I am connected to my vcenter, new-scsi complains that it needs to be connected to esx. If I'm connected to the esx, then it wants the vcenter.

 

My next thought was to connect to both and see what happens, but I get the same issue as when running esx, it complains about being restricted to the vcenter.

 

Any help on this would be greatly appreciated! Thanks


saving multiple vcenter cred using New-VICredentialStoreItem

$
0
0

Hi folks

 

How to save multiple vcenters credentials in single .xml file and call single vcenter once using that .xml file.

ex:

$vcenterserver="vcenter1","vcenter2","vcenter3","vcenter4"

New-VICredentialStoreItem -Host $vcenterserver  -User domain\domainuser -Password 'password' -File "C:\cred.xml"

its fail with below error

vicrederror.JPG

 

after executing as below if i supply host values "vcenter1","vcenter2","vcenter3","vcenter4" then its saving in .xml

New-VICredentialStoreItem   -User domain\domainuser -Password 'password' -File "C:\cred.xml"

Import-VApp slow & times out

$
0
0

I have to import 7 virtual machines to about 100 hosts. All machines vary in size, are Windows Server. My original script uses Import-VApp. However one machine is failing on import, the largest one. This one is  is 2.8Tb in size - across 6 disks after import completes. Actual OVF size is about 15Gb

If I import using Import-VApp, standard settings then it gets to about 90% then crashes with the error The object has already been deleted or has not been completely created."

We are importing to a standalone host (not vCenter)

The OVF can be imported through the GUI, or thin provisioned through Import-VApp, just not thick lazy through Import-VApp! I have seen a timeout message in the console when running the import,, but have not been able to find any references so far to timeout settings relating to imports, just moves and so on. 

I can do it through ovftool - but have seen a few strange hangs with that, whereas all my other machines import quite happily with Import-VApp, and I haven't seen any hangs / crashes  (7 machines per host). Does anyone know what timeout it is hitting?

 

 

 

Scan-Inventory -> Test-Compliance... Operation is not valid due to the current state of the object

$
0
0

Hi,

 

I'm working on a script to patch our single ESXi hosts. But the Scan-Inventory command gives me an error although it is executed  successfully and the host was put into maintenance mode.

 

...

Get-VMHost -Name $esxi | Set-VMHost -State Maintenance -Confirm:$false | Out-Null

Scan-Inventory -Verbose -Entity $esxi -UpdateType HostPatch

...

 

VERBOSE: 08.07.2016 09:36:42    Test-Compliance    Started execution

VERBOSE: Performing operation 'Scan Inventory' on target: 'xxxxxx'

VERBOSE: 08.07.2016 09:36:47    Test-Compliance    Finished execution

Scan-Inventory : 08.07.2016 09:36:47    Test-Compliance        Operation is not valid due to the current state of the object.  

At D:\VMware_Skripte\patch_host.ps1:51 char:1

+ Scan-Inventory -Verbose -Entity $esxi -UpdateType HostPatch

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

    + CategoryInfo          : NotSpecified: (:) [Test-Compliance], VimException

    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VumAutomation.Commands.ScanInventory

 

 

vCenter Tasks/Events

Scan entity xxxxx Completed xxxxx xxxxx 08/07/2016 09:28:55 08/07/2016 09:28:55 08/07/2016 09:29:10

Enter maintenance mode xxxxx Completed xxxxx xxxxx 08/07/2016 09:28:38 08/07/2016 09:28:38 08/07/2016 09:28:38

 

 

I don't see what the problem could be, any ideas?

 

Edit: Remediate also fails

Remediate-Inventory : 08.07.2016 10:16:39Update-Entity    Operation is not valid due to the current state of the object.   

At D:\VMware_Skripte\patch_host.ps1:57 char:1

+ Remediate-Inventory -Baseline $baselines -Entity $esxi -Confirm:$false

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

+ CategoryInfo      : NotSpecified: (:) [Update-Entity], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VumAutomation.Commands.RemediateInventory

Merge Multiple email outputs to singlemail

$
0
0

Hi all,

Can someone help me to complete this script.

My question is with the below script I can send error report of each vcenter as a single mail but I need all the connected vcenter error report output in a singlemail.

$allvcenterservers = "vcenter1","vcenter2","vcenter3","vcenter4"
foreach($vcenterserver in $allvcenterservers){
$cred = Get-VICredentialStoreItem -User domain\user -Host $vcenterserver  -File C:\cred.xml
Connect-VIServer -Server $cred.Host -User $cred.User -Password $cred.Password | Out-Null
$daysback = 1
$report = @()
$report+= Get-VIEvent -Types Error -maxsamples ([int]::MaxValue) -Start (Get-Date).AddDays(-$daysback) |
Select @{N="Vcenterserver";E={$vcenterserver}},
@{N="Type";E={$_.GetType().Name}},
@{N='CreatedTime';E={$_.CreatedTime}},
@{N='User';E={$_.UserName}},
@{N="Message";E={$_.FullFormattedMessage}}
$CurrentDate = Get-Date -Format 'MM-dd-yyyy_hh-mm-ss'
$filename = "C:\eventreport on $vcenterserver -$($CurrentDate).csv"
if($report.Count -eq 0){
}
else{
$report |Export-Csv -Path $filename -NoTypeInformation -NoClobber -UseCulture
Send-MailMessage -From "vineeth@mail.com" -To "vineeth@mail.com" -Subject "Error Events on $vcenterserver" -Body "The attachment contains all error events which are triggered from past 24hrs on $vcenterserver" -Attachments $filename -SmtpServ.com'
}}

Invoke-Command to Newly Created Virtual Machines

$
0
0

Hi Everybody,

 

I have been attempting @ getting something to function courtesy of some powershell cmdlets/powercli.  I want to invoke-command and call to an exe/msi when a new virtual machine is created (to install applicable 3rd party storage application in this case).  Have a workflow that clones the virtual machine, and then invokes a powershell command.  Pretty straight forward here.  My concern comes with the names of the virtual appliances will always change.  Would anyone know of a variable I can pass to query this newly created virtual machine during deployment.  Any input would be greatly appreciated.

Viewing all 16717 articles
Browse latest View live


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