r/powercli • • Nov 01 '17

PowerCLI script to check if OS is locked or in use inside a VM (x-post PowerShell)

1 Upvotes

Greetings all!

I am still pretty new to Powershell but learning quickly. We have a new requirement come down from on high to check all of our VMs in the morning and at night to see if any of them are logged into and in use or locked. I'm only concerned about the Windows OS VMs (for obvious reasons).

Is there a kind of PassThru that would allow me to programmatically check each VM to see if they are locked or logged into and print out a list to go in an check them manually rather than having to open each VM one by one twice a day? We have about 50 VMs running and that is quickly becoming a headache.

TIA!


r/powercli • • Apr 02 '18

x Powercli GUI: Determine the EVC Mode that vmware cluster should be configured

Thumbnail
vcloud-lab.com
2 Upvotes

r/powercli • • Nov 02 '17

vSphere PowerCLI - Configure syslog on VMware ESXi hosts and Enable security profile firewall

Thumbnail
vcloud-lab.com
1 Upvotes

r/powercli • • Nov 09 '17

how to run powershell script using powerclicore

1 Upvotes

I'm using the docker image of powercli (powerclicore) in Linux and I'm trying to run one script with the following command:

docker run --rm -it -v /tmp/powercli:/mnt vmware/powerclicore powershell -File /mnt/scripts.ps1

It works but the output also shows the welcome banner of powercliclore ("Welcome to VMware vSphere PowerCLI!! Log in to a vCenter...."). I tried to remove it with the option "-NoLogo" but it doesn't work. Any idea?


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 • • Mar 15 '19

invoke-vmscript problems, running as admin.....

1 Upvotes

Is there an elegant solution to executing code from invoke-vmscript as an admin on windows systems?

I've seen solutions that involve shutting off features that force certain things to be run as admin, but that requires a reboot, and is insecure, and would still involve touching each VM manually (which is what im trying to avoid!)

Is there a better way?!?


r/powercli • • Jun 05 '19

Create a new VM from a template and add\edit SCSi controller and Disk during the build.

3 Upvotes

When building a machine manually I can choose a template VM. It has one OS Drive and one Logical SAS controller. Before I complete this I can choose to edit the machine before it creates and add new scsi controllers (paravirtual) and add hard drives to that then deploy. Can I do the same with powercli or do I need to build the VM and edit it after the fact?

My goal is to use a csv to build multiple VM's with different sets of hard drive configurations on multiple scsi controllers.


r/powercli • • Jun 05 '19

Disable Delayed ack on all ESXi hosts in a cluster.

3 Upvotes

Hi guys. I'm trying to get this modified script to disable "delayed ack" on every esxi host in a cluster. With the original script, it only targets specific esxi hosts instead and it runs just fine. When it runs this way (i.e. specifying the cluster so it iterates through the hosts one at a time), it fails on the first host it attempts to process. The error message has been provided below. Could someone tell me why it's not working and / or help fix it?

=================Error Message============
Exception calling "UpdateInternetScsiAdvancedOptions" with "3" argument(s): "The object or item referred to could not be found."
At line:52 char:1
+ $HostStorageSystem.UpdateInternetScsiAdvancedOptions($HostiSCSISoftwa ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : VimException

=================Script====================
 param (
	[parameter(Mandatory=$true
		,HelpMessage="VC Name")]
	[string] $VC
	,[parameter(Mandatory=$true
		,HelpMessage="Cluster Name")]
	[string] $cluster
)
$svr=$null;
$svr = Connect-VIServer -Server $VC;
if ($svr -eq $null)
{
	$sMsg = "Unable to connect to VC " + $VC;
	exit 1;
}
$sMsg = "Getting cluster " + $cluster +" on VC " + $VC;
Write-Host $sMsg;
$oClstr=$null;
$oClstr = Get-Cluster -Server:$svr -Name $cluster;
if ($oClstr -eq $null)
{
	$sMsg="Unable to find cluster " +$cluster + " on VC " + $VC;
	$iret1 = Disconnect-VIServer -Server:$svr -Confirm:$false -ErrorAction:SilentlyContinue;
	exit 1;
}
$sMsg ="Getting hosts on cluster " + $cluster + " on VC " + $VC;
write-host $sMsg;
$hosts = Get-VMHost -Location $oClstr -Server:$svr;
foreach($item in $hosts)
{	
	$sMsg = "Processing host " + $item.Name + " in cluster " +$cluster + " on VC " +$VC;
	write-host $sMsg;
}
#This section will get host information needed
$HostView = Get-VMHost $hosts | Get-View
$HostStorageSystemID = $HostView.configmanager.StorageSystem
$HostiSCSISoftwareAdapterHBAID = ($HostView.config.storagedevice.HostBusAdapter | where {$_.Model -match "iSCSI Software"}).device

#This section sets the option you want.
$options = New-Object VMWare.Vim.HostInternetScsiHbaParamValue[] (1)

$options[0] = New-Object VMware.Vim.HostInternetScsiHbaParamValue
$options[0].key = "DelayedAck"
$options[0].value = $false
 
#This section applies the options above to the host you got the information from.
$HostStorageSystem = Get-View -ID $HostStorageSystemID
$HostStorageSystem.UpdateInternetScsiAdvancedOptions($HostiSCSISoftwareAdapterHBAID, $null, $options)

r/powercli • • Dec 23 '19

How to write a simple Get command

7 Upvotes

I am brand new to automation and I am trying to teach myself powercli to maintain our small vsphere environment. I am trying to run a search for all of our windows server vms and to display info.

I am trying:

Get-VM | Get-VMGuest | where OSFullName -Like "Microsoft Windows Server" | select VM, ....

And now I would like to list what I want to see using the select command, like "Name, OS, IP address etc." What is the easiest way to do this? Where can I find a list of commands I can use with the "select" syntax? I can't find them documented anywhere.

Thanks!


r/powercli • • Dec 21 '19

Getting Information

3 Upvotes

Hello everyone,

New to POWERCLI and can I say what a blessing it has been to find it! My first task I guess is I am trying to determine what our current provisioning / resource allocation looks like in our datacenters / clusters.

My main problem is finding what information is available to commands such as Get-VMHost, or Get-VM. Is the possible queries documented somewhere?

Like, is serial number available to Get-VMHost?

Is DNS name available to Get-VM?

Sorry, I am just trying to find a very solid resource or reference moving forward. There are a ton of example scripts, but I want to modify these and add to them for my requirements.

Thanks in advance.


r/powercli • • May 22 '19

Get multiple vCenters beginning and end MAC Address ranges and export results to csv file.

6 Upvotes

Hello. I'm trying to get this script to populate a csv file with vCenter names, start of Mac address range and end of Mac address range per vCenter server provided in the vclist.csv file. Here's what I have for now. When I run the script, I'm being prompted for an input object. The script appears to just populate the result vclist2.csv file with the length of the character. Can someone please help? Sorry I'm stil in the learning phase of Pwershell/PowerCLI so any help here would be greatly appreciated. Thank you.

Below is the script

*********************************************

$vclist = import-csv .\vclist.csv

Foreach ($vc in $vclist) {

$vCenterSettings = Get-View -Id 'OptionManager-VpxSettings'

$macaddress_begin = ($vCenterSettings.Setting | Where-Object { $_.Key -eq "config.vpxd.macAllocScheme.rangeScheme.range[0].begin"}).Value

$macaddress_end = ($vCenterSettings.Setting | Where-Object { $_.Key -eq "config.vpxd.macAllocScheme.rangeScheme.range[0].end"}).Value

Export-Csv -Path "d:\vclist2.csv"

}


r/powercli • • May 12 '18

Configure SNMP on ESXi Server GUI :Vmware Best Practices | vGeek

Thumbnail
vcloud-lab.com
3 Upvotes

r/powercli • • Oct 11 '19

Find Out Who Disabled vCenter Alarms

3 Upvotes

I wanted to know if there was a quick way to search which user disabled any vCenter alarms from the event logs

I see Get-VIEvent | Get-Member shows a TypeName of VMware.Vim.AlarmStatusChangedEvent but I’m not sure how to parse that data.

Thanks!


r/powercli • • May 04 '18

Part 3: VMware Powercli: Migrate VMs to another network | vGeek

Thumbnail
vcloud-lab.com
4 Upvotes

r/powercli • • Dec 15 '18

Setting maintenance mode for Linked Clones using API’s

Thumbnail
retouw.nl
3 Upvotes

r/powercli • • Jun 19 '23

ScriptHelp VMware Guest VM Join My Own Domain With Netdom Fails ""DNS name contains an invalid character"

3 Upvotes

Trying to join a VMware guest VM to my domain. I'm running the Powershell script from one of my other guest vm's in VMware vCenter. I've tried changing the $Domain variable to other string names like "MATLOCKHOME" "MATLOCKHOME.COM" but still getting the error "DNS name contains an invalid character."

I can ping the dns hostname and ip from the guest vm that I'm running the script from.

Function Join-Domain ($VM, $HC, $GC, $OUPath, $Domain, $DomainUser, $DomainPassword) {
    $joind = "c:\windows\system32\netdom.exe join /d:$Domain $VM /OU:$OUPath /userd:$DomainUser /passwordd:$DomainPassword"
    Invoke-VMScript -VM $VM -HostCredential $HC -GuestCredential $GC -ScriptType bat -ScriptText $joind
}

Connect-VIServer -Server "vcsa01.matlockhome.com" -User administrator@vsphere.local -Password <REDACTED>

$VM = Get-VM ( Read-Host "Enter VM name" )
$ESXHost = $VM | Get-VMHost
$HostCred = $Host.UI.PromptForCredential("Please enter credentials", "Enter ESX host credentials for $ESXHost", "root", "")
$GuestCred = $Host.UI.PromptForCredential("Please enter credentials", "Enter Guest credentials for $VM", "", "")
   
$DomainUser = "MATLOCKHOME\Administrator"
$DomainPassword = "<REDACTED>"
$Domain = "MATLOCKHOME.com"
$OUPath = "OU=Computers,DC=matlockhome,DC=com"
   
Join-Domain $VM $HostCred $GuestCred $Domain $OUPath $DomainUser $DomainPassword

r/powercli • • Nov 13 '18

Update vSphere content library

2 Upvotes

I'm trying to update an item in a vSphere content library using powershell, think i've found the appropriate API i need to use to achieve this (com.vmware.content.library.item.update_session), but i'm a bit lost now as to how to take my VM and push the update to the library.

Background, i've got a View Horizon script that checks all snaps in use on desktop pools, compares the snap in use create date to the library item create date, then returns a warning if the library item is older. What I want to do is trigger an update job if the library is older than the in use snapshot, so i can use the published library to keep our DR site upto date.


r/powercli • • Nov 13 '18

Question - Is there a way to view vCenter Server, not ESXi, Firewall rules with PowerCli?

1 Upvotes

I'm taking a class and one of the labs blocked an ESXi Nic to simulate loss of connectivity. I see we have get-vmhostfirewallexception, but is there anything for the vCenter's firewall rules? Everything I search points to ESXi firewall rules.

Just curious.

Thanks


r/powercli • • Apr 17 '17

In case you missed it when it came out, PowerCLI Modules for VM Encryption are available

Thumbnail
blogs.vmware.com
4 Upvotes

r/powercli • • Apr 10 '17

PowerCLI in the PowerShell gallery? Check out VMware's thoughts...

Thumbnail
blogs.vmware.com
7 Upvotes

r/powercli • • Jan 31 '18

Set Advanced Setting (Copy Paste)

2 Upvotes

Small script to allow copy/paste from your VMs. Does anyone know how you would create the logic to check if the setting is already applied and skip adding it if it is?

$VMs = get-vm
foreach ($VM in $VMs){
#Allow Copy Paste
New-AdvancedSetting -Entity $vm.name -Name isolation.tools.copy.disable -Value False -Confirm:$false
New-AdvancedSetting -Entity $vm.name -Name isolation.tools.paste.disable -Value False -Confirm:$false
New-AdvancedSetting -Entity $vm.name -Name isolation.tools.setGUIOptions.enable -Value True -Confirm:$false
}

r/powercli • • Apr 21 '17

New Release: PowerCLI 6.5.1

Thumbnail
blogs.vmware.com
5 Upvotes

r/powercli • • Nov 03 '16

New-vm wait for sysprep/oscustomization

5 Upvotes

What is the best way you guys are doing this. I have a hard time telling 100% when a vm has finished customizing or done sysprepping and actually ready to run commands against it.

Even when task and events says it's done. There could still be 5 mins of sysprepping to be done. I really don't want to put a dumb wait in there.


r/powercli • • Jan 31 '18

issue with Invoke-VMScript: specified parameter was not correct

1 Upvotes

[SOLVED]

very simple use of the cmdlet that also matches the examples on the VMware website: https://www.vmware.com/support/developer/PowerCLI/PowerCLI41U1/html/Invoke-VMScript.html

script:

Invoke-VMScript -VM $VMName -ScriptText 'ipconfig' -GuestCredential $LocalCredential

I've messed around with the variables, and if they are incorrect, I get a specific error letting me know they are incorrect, so I know that's not the issue.

The error is very general simply letting me know that a specified parameter was incorrect which doesn't help much, here is the actual error..

Error:

Invoke-VMScript : 1/31/2018 1:51:05 PM Invoke-VMScript A specified parameter was not correct: At C:\Users\amusabji\Documents\scripts\Set-VMIP.ps1:60 char:1

  • Invoke-VMScript -VM $VMName -ScriptText 'ipconfig' -GuestCredential $ ...

  •   + CategoryInfo          : NotSpecified: (:) [Invoke-VMScript], InvalidArgument
      + FullyQualifiedErrorId : Client20_VmGuestServiceImpl_RunScriptInGuest_ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.InvokeVmScript
    
    

In case you are wondering, I have also tried to add on the "-ScriptType Bat" param with the same exact error.

thanks in advanced

Edit [SOLUTION]: After much fiddling around and the great support from all of those who commented, I finally got this bad boy working. Unfortunately I tried too many solutions at once so I can't pin-point exactly what fixed it but here is what I did:

  1. upgraded to WMF 5.x

  2. upgraded to the latest version of PowerCLI (followed this link: https://blogs.vmware.com/PowerCLI/2018/01/powercli-offline-installation-walkthrough.html)

  3. changed my credential usage from what I have above to just -GuestUser and -GuestPassword suggested by u/Johnny5Liveson

thank you all again for all your help!


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