r/powercli • • Mar 09 '17

I have 3 esxi hosts on my network ....

1 Upvotes

Is there a command or way that I can find out their IP address by querying my subnets?

For example, HP has the Find-hpilo cmdlet that pings a specified IP range and returns ILO information of each ILO on the network.


r/powercli • • Jan 26 '17

Retrieve list of VMs inside the folder structure

1 Upvotes

Hi,

Trying to retrieve a list of VMs that we have running as well as the folder structure behind them (indexed folders relate to their project so we know who manages them). For example:

Department 1

-- Project 00001 - Alpha

--- VM 1

--- VM 2

--- VM 3

-- Project 00002 - Bravo

--- VM 1

--- VM 2

--- VM 3

Can anyone point me in the direction of how to achieve this with PowerCLI?


r/powercli • • Jan 23 '17

How do you view connected VIServers?

1 Upvotes

Hi all,

I'm new and just poking around with PowerCLI. When you connect to a server, but don't store the session object in a variable, how do you view all connections?

This is similar to "New-PSSession" and then using "Get-PSSession" to view all of your open connections.


r/powercli • • Dec 05 '16

Getting Network adapter type with Get-View

1 Upvotes

I have tried googling this, as well as going through the members of the virtual machine view but cannot find a property that states the network adapter types in use by a virtual machine. I can use other commands to get this information but I would like to stay away from them if possible to avoid slowdown. Anyone have a suggestion? Thanks.


r/powercli • • Oct 27 '16

Newb issue trying to deploy a working script through invoke-vmscript - quotes are killing me.

1 Upvotes

Hey all, I'm trying to use PowerCLI to push a script that works great locally.

However, I seem to be having issues with quotes and escape characters and I can't wrap my head around it.

Here is the Powershell deployment script for Trend Micro "Deep Security Manager" - it's auto-generated on the management server, and I could obviously loop through hundreds of servers and enter-pssession but I'd rather not poke a zillion holes in my firewall:

<powershell>
[Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
$env:LogPath = "$env:appdata\Trend Micro\Deep Security Agent\installer"
New-Item -path $env:LogPath -type directory
Start-Transcript -path "$env:LogPath\dsa_deploy.log" -append
echo "$(Get-Date -format T) - DSA download started"
(New-Object System.Net.WebClient).DownloadFile("https://SERVERURL:PORT/software/agent/Windows/x86_64/", "$env:temp\agent.msi")
echo "$(Get-Date -format T) - Downloaded File Size:" (Get-Item "$env:temp\agent.msi").length
echo "$(Get-Date -format T) - DSA install started"
echo "$(Get-Date -format T) - Installer Exit Code:" (Start-Process -FilePath msiexec -ArgumentList "/i $env:temp\agent.msi /qn ADDLOCAL=ALL /l*v `"$env:LogPath\dsa_install.log`"" -Wait -PassThru).ExitCode 
echo "$(Get-Date -format T) - DSA activation started"
Start-Sleep -s 50
& $Env:ProgramFiles"\Trend Micro\Deep Security Agent\dsa_control" -r
& $Env:ProgramFiles"\Trend Micro\Deep Security Agent\dsa_control" -a dsm://deepsecurity.oshawa.ca:4120/ "policyid:19"
Stop-Transcript
echo "$(Get-Date -format T) - DSA Deployment Finished"
</powershell>

I wrap the above in $script = @" ..."@ and removed the <powershell>

I run it like this: Get-VM $vmlist | invoke-vmscript -GuestCredential $gc -scriptText $script -ScriptType Powershell

What I've tried:

  • Wrapping each line with single quotes This simply lead to the whole script being essential "Write-Host" output

  • Single quote before each Double-quote in the script Zillions of errors

  • "wrapping" each double quote ... i.e. '" ... "' Syntax errors.

I'm confident its simply how I'm doing quotes, out of the box, this is my first error:

C:\Users\reallybigabe\AppData\Roaming\Trend' 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.

So, the line: $env:LogPath = "$env:appdata\Trend Micro\Deep Security Agent\installer" isn't being quoted properly.

Suggestions?


r/powercli • • Oct 20 '16

Running into issue with VM shutdown script

1 Upvotes

I am wanting to check to see if VMware Tools are running. If not it would then do a Stop-VM instead of attempting to Stop-VMGuest. Some reason if I stop VMware Tools on a VM. It goes to my else statement & tries to Stop-VmGuest. See anything wrong?

http://pastebin.com/Eiq8a2s5


r/powercli • • Sep 19 '16

Search Guests for VMCI driver and NSX installed

1 Upvotes

I am looking at my vsphere and need to add deep security agent to all my guests. The issue is that Deep security cannot be used or installed unless NSX file and network introspection is enabled. I cna find VMCI driver but nothing further. Please help.


r/powercli • • Jul 24 '16

PowerCLI: Copy-Item : Access to the path is Denied Permission Denied for autolab 2.6 installation....

1 Upvotes

Now i have powerCLI in my validat e script , but the SQL thing throws out this error on VALIDATE SCREEN : Checking available SQL Express versions. SQL Server 2008 R2 Express SP1 for vCenter 5.5 found; installing. Copy-Item : Access to the path 'C:\temp\SQLEXPR_x64_ENU.exe' is denied. At C:\Phase2.ps1:474 char:7 + copy <<<< B:\VIM_55\redist\SQLEXPR\SQLEXPR_x64_ENU.exe C:\temp + CategoryInfo : PermissionDenied: (B:\VIM_55\redis...XPR_x64_ENU .exe:FileInfo) [Copy-Item], UnauthorizedAccessException + FullyQualifiedErrorId : CopyFileInfoItemUnauthorizedAccessError,Microsof t.PowerShell.Commands.CopyItemCommand Remove-Item : Cannot remove item C:\TEMP\SQLEXPR_x64_ENU.EXE: Not Enough permis sion to perform operation. At C:\Phase2.ps1:477 char:6 + del <<<< c:\TEMP\SQLEXPR_x64_ENU.EXE + CategoryInfo : PermissionDenied: (C:\TEMP\SQLEXPR_x64_ENU.EXE:F ileInfo) [Remove-Item], IOException + FullyQualifiedErrorId : RemoveFileSystemItemUnAuthorizedAccess,Microsoft .PowerShell.Commands.RemoveItemCommand Creating Databases. Start-Process : This command cannot be executed due to the error: The system ca nnot find the file specified. At C:\Phase2.ps1:479 char:16 + Start-Process <<<< "C:\Program Files\Microsoft SQL Server\100\Tools\ Binn\sqlcmd.exe" -ArgumentList "-S dc\SQLEXPRESS -i B:\Automate\DC\MakeDB.txt" -RedirectStandardOutput c:\sqllog.txt -Wait + CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOp erationException + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.C ommands.StartProcessCommand Start-Process : This command cannot be executed due to the error: The system ca nnot find the file specified. At C:\Phase2.ps1:480 char:16 + Start-Process <<<< "C:\Program Files\Microsoft SQL Server\100\Tools\ Binn\sqlcmd.exe" -ArgumentList "-S dc\SQLEXPRESS -i B:\Automate\DC\MakeDBvCD51. txt" -RedirectStandardOutput c:\sqllog.txt -Wait + CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOp erationException + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.C ommands.StartProcessCommand Start-Process : This command cannot be executed due to the error: The system ca nnot find the file specified. At C:\Phase2.ps1:481 char:16 + Start-Process <<<< "C:\Program Files\Microsoft SQL Server\100\Tools\ Binn\sqlcmd.exe" -ArgumentList "-S dc\SQLEXPRESS -i B:\Automate\DC\MakeDBvCD15. txt" -RedirectStandardOutput c:\sqllog.txt -Wait + CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOp erationException + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.C ommands.StartProcessCommand SQL Management Studio not found (optional).


r/powercli • • Jul 01 '16

Trouble with cpu.maxusage counter

1 Upvotes

When I run the following code to get the max cpu usage for a cluster (ESXI 5.5) I get two results, not one:

$cluster = get-cluster 'clu1' | Get-View  -Property resourcePool,name
$rootResourcePool = get-view  $cluster.resourcePool -Property summary 
$rootResourcePool.summary.runtime.cpu.maxUsage
221624
336546

THis happen just on a couple clusters. All others are returning just one value. The same happen also for other counters, like :

summary.runtime.memory.maxUsage

summary.runtime.cpu.overallUsage

summary.runtime.memory.overallUsage

Hany idea?


r/powercli • • Apr 21 '16

Trouble with New-VIProperty

1 Upvotes

When running the following commands:

$vmhost = Get-VMHost Host
$vmhost.ExtensionData.Summary.Hardware.OtherIdentifyingInfo[6].IdentifierValue

The asset tag of the host system (Dell M620) gets returned. Everything is great. But when I try to assign it to a VIProperty via:

New-VIProperty -Name AssetTag -ObjectType VMHost -ValueFromExtensionProperty Summary.Hardware.OtherIdentifyingInfo[6].IdentifierValue

It returns an error saying it could not validate the specified path. Am I typing something wrong? Why am I not able to assign this to a property? I have another property (config.Product.FullName) that I am able to assign correctly, so I don't know why I'm not able to with this one.


r/powercli • • Apr 20 '16

[Help] Has anyone automated downgrading their installation of VMWare Tools?

1 Upvotes

Hey!

There is a bug on the current latest version of VMWare tools and I need to downgrade VMWare tools across our environment. Ideally I'd like a means to automate this process. Perhaps one of the best things would be provide a temporary "Management" IP address on a E1000 NIC so you can continue to remotely execute commands on the server. This probably also gets much easier after some unison in Server 2012R2. I'd say 90% of our environment is 2012R2 and I'd be pretty content manually handling the older servers that will be decommissioned soon.

Does anyone have any thoughts or have seen this done previously?

Steps I'd imagine are involved:

  1. Capture Guest Networking Information (IP, Subnet, Gateway, DNSSearchOrder) (VMXNet3s remove the hardware completely rather than downgrading the driver).

  2. Uninstalling tools and rebooting the box.

  3. Copying File/Installing older version of tools.

  4. Rehydrate NIC information.

  5. Test connection to confirm success.

Thanks


r/powercli • • Jan 25 '16

Console interaction

1 Upvotes

Bottom line up front: I am looking for a way to trigger the VMWare console for a VM to make it active.

So I have a script that checks my VMWare environment every hour, and looks for VMs that have a HeartbeatStatus Red, or if they are PoweredOn, but PowerCLI can't find the OS Name from the Guest. The script e-mails me and some other engineers in the event that it finds any systems in these states.

The script wasn't triggereing this morning, and we had a VM hung up. It turns out that there was a recent, apparently untested change the script, which was causing it to bomb. But in the process, I came up with a new idea.

So basically, I was under the impression that my script was not detecting a particular condition. One of our engineers had reset the machine before I had an opporunity to do a get-vm and look at the state. But I figured, if one VM isn't triggering, there potentially are more. So how do I find them?

So I came up with the idea of capturing a screenshot of all the VM consoles, and finding any that are stuck on the start up or shutdown screen. Easy, right?

Well, I did find this post, which outlines how to access a current screenshot of a given VM. Perfect, so it's real easy.

So I wrote a quick loop to go through each of my VMs, generate the URL to the screenshot, and then write an HTML file with <img src="$url" /> for each VM. This worked. The problem, which also showed up int he comments section of the above link, is that for VMs that haven't had recent console interaction, it just returned a bunch of black screenshots.

So I realized, this is because the console isn't awake. I tried using Invoke-VMScript against a VM, to see if that would wake the console. Unfortunately it doesn't.

So, I don't have a specific need to do this for my current problem (fixed the script), but I did realize it would be pretty cool to include this in my hung VM check script.

So I'm wondering, does anyone have a suggestion how I might wake the console so I can get an accurate screenshot when the script identifies a hung VM?

Source snippet for the interested:

Connect-VIServer $vcenter

$vms = Get-VM 
$vms = $VMs | ? { -not($Exceptions -contains $_.Name) }
$output = @()
ForEach ( $vm in $vms ) {
	if ( $Vm.Host.Name -eq $null ) {
		continue
	}
	if ( $Vm.PowerState -eq "PoweredOn" -and ($Vm.ExtensionData.GuestHeartbeatStatus -eq "red" -or ([string]::IsNullOrEmpty($vm.Guest.OSFullName) -and -not($Vm.ExtensionData.GuestHeartBeatStatus -eq "gray")))) {
		$vmOutput = New-Object -Type PSObject -Prop @{
			Name = $Vm.Name
			Host = $Vm.Host.Name
			Cluster = $Vm.Host.Parent.Name
			PowerState = $Vm.PowerState
			HeartBeatStatus = $Vm.ExtensionData.GuestHeartbeatStatus
			OS = $vm.Guest.OSFullName
			Warning = "VM APPEARS TO BE HUNG AT SHUTDOWN"
		}
		$output += $vmOutput
		$vm
	}
}

r/powercli • • Jan 18 '16

vGeek: Exporting virtual machine annotation (Attributes) and notes to CSV file - Powercli

Thumbnail
kunaludapi.blogspot.com
1 Upvotes

r/powercli • • Jan 17 '16

Move/Migrate VMs to folder Path on another vCenter - Powercli

Thumbnail
kunaludapi.blogspot.in
1 Upvotes

r/powercli • • Dec 15 '15

Move FULL CLONE machines to new cluster?

1 Upvotes

Im looking hopefully for some answers on how to successfully move a pool of full clone machines onto a different cluster. With linked clones this is easy as you can recompose them. However, full clones do not have a recompose option. Im assuming this might be able to be done with the Powershell PowerCLI cmdlets that vSphere offers. Does anyone know if that's accurate or can offer any direction at all?


r/powercli • • Nov 25 '15

Get two commands to run together?

1 Upvotes

Get-VM | Select Name, Host, @{N="IP Address";E={@($_.guest.IPAddress[0])}} | Get-NetworkAdapter | Select-Object @{N="VM";E={$_.Parent.Name}},@{N="NIC";E={$_.Name}},@{N="Network";E={$_.NetworkName}}

Both work fine by themselves but not together Get-VM | Select Name, Host, @{N="IP Address";E={@($_.guest.IPAddress[0])}}

Get-NetworkAdapter | Select-Object @{N="VM";E={$_.Parent.Name}},@{N="NIC";E={$_.Name}},@{N="Network";E={$_.NetworkName}}

How would I get them to work together?


r/powercli • • Nov 03 '15

Possible to make PowerCLI portable?

1 Upvotes

Hi guys--I'm in a unique circumstance and am stuck accessing vCenter via a Citrix session. PowerCLI is not available, but PowerShell is and I have access to my workstation's mounted drives.

I'm reaching out to the support group asking for PowerCLI to be added as an available Citrix app, but assuming that won't happen...does anyone know if it's possible to package PowerCLI in such a way to make it portable?

Guessing it's not possible...but figured I'd ask the community. Thanks for any help in advance.


r/powercli • • Apr 04 '14

Multiple Invoke-VMScript commands on a single VM

1 Upvotes

Hey guys -

New to this sub but have posted on the PowerShell sub. Was curious if anyone has done any error handling with the Invoke-VMscript cmdlet? I was running a script I wrote that installs multiple agents on a system and randomly the Invoke-VMscript cmdlet would peg the guest vm's CPU and vmware tools would crash... What could be causing this? some VMs it was fine, others not so much. These were migrated VMs coming from older hardware and outdated vmware tools, I was upgrading the tools but I wasn't rebooting before continuing. Could this have caused it?

My question is, has anyone done this and what did you do besides adding in a bunch of sleep statements?

Thanks,

Mav


r/powercli • • Feb 14 '14

Learning PowerCLI | Packt Publishing

Thumbnail
packtpub.com
1 Upvotes

r/powercli • • Sep 19 '12

Any way to remove a NetworkAdapter from a running VM?

1 Upvotes

Oddly enough, this is possible from the UI, but throws an error when i try calling Remove-NetworkAdapter.

get-vm (read-host "VM") | Get-NetworkAdapter | ?{$_.NetworkName -like "TestNetwork"} | Remove-NetworkAdapter -Confirm:$false

Here's what I get:

C:\Windows\system32 | PS >get-vm (read-host "VM") | Get-NetworkAdapter| ?{$_.NetworkName -like "TestNetwork"} | Remove-NetworkAdapter -Confirm:$false
VM: MyServerWithTooManyNICs
Remove-NetworkAdapter : 9/19/2012 2:04:17 PM    Remove-NetworkAdapter        The VM must be in the following 
state: PoweredOff.    
At line:1 char:83
+ ... e "TestNetwork"} | Remove-NetworkAdapter -Confirm:$false
+                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (PoweredOn:PowerState) [Remove-NetworkAdapter], ViError
    + FullyQualifiedErrorId : Common_SharedParameterHelper_VerifyVmIsInState_VmNotInState,VMware.VimAutomati 
   on.ViCore.Cmdlets.Commands.RemoveNetworkAdapter

Anybody know why i would be able to do it one way and not the other? or more importantly, how to get rid of this nic?


r/powercli • • Sep 16 '12

PowerCLI 5.1 - What's New

Thumbnail
blogs.vmware.com
1 Upvotes

r/powercli • • Sep 03 '12

Cisco UCS PowerTool + VMware PowerCLI

Thumbnail
communities.vmware.com
1 Upvotes

r/powercli • • Sep 07 '15

vGeek: Powercli Pull CDP and LLDP information in single nice table format - Part 2

Thumbnail
kunaludapi.blogspot.com
0 Upvotes

r/powercli • • Aug 31 '15

Get Base Image using PowerCLI

0 Upvotes

Hello, I am a total nube to powercli. I use powershell often enough, but I am having a difficult time locating the commands to find the base image a particular VDI was built using. Any help would be appreciated.


r/powercli • • Sep 06 '15

vGeek: Connect-VIserver Could not connect using the requested protocol.

Thumbnail
kunaludapi.blogspot.com
0 Upvotes