Below you will find pages that utilize the taxonomy term “Scripting”
Posts
Men and Mice API Client Gem for Ruby
Part of what I am doing these days is integrating Red Hat CloudForms / ManageIQ with the Men and Mice IP address management (IPAM) application. In order to reduce gem dependencies, reduce duplication, and handle some architecture issues I have been working on a client gem that uses the JSON-RPC API provided by Men and Mice.
If you are using Ruby and want to integrate with M&M please check out the gem and provide any feedback you have through Github issues.
Posts
Foreman ESXi Installation Never Completes
In our environment we want to use Foreman to build our OCP hardware. It was working well except that the installation would repeatedly PXE boot to reinstall because Foreman would not know that the PXE portion was complete.
The standard notification code below was failing for some reason.
1 2 %post --interpreter=busybox --ignorefailure=true wget -O /dev/null <%= foreman_url %> After running the unattended install in a Fusion VM so I could have console access I reviewed the install log and a misleading message from wget about the URL being bad.
Posts
Single pane for multiple vCenter alarms
When you have multiple vCenters it can be a pain to go through each one checking for alarms. Hence the script below. You can specify the vCenters you want to connect to and it will display a nice sortable/filterable grid view of all of the triggered alarms.
# Usage .\Get-TriggeredAlarms -vCenters vc001,vc002 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 param ( [String[]]$vCenters ) Function Get-TriggeredAlarms { param ( $vCenter = $(throw "A vCenter must be specified.
Posts
PowerShell: Alternate script behavior when dot sourced vs run directly
I use dot sourcing in my PowerShell scripts to reuse functions* and sometimes I want different behavior if they are included (dot sourced) or run directly. This concept is used in Python to provide an easy way to run tests against the code when run directly but not when it is imported.
You are not restricted to running tests using this approach, but I think that automated testing is useful so that is the example I provide below.
Posts
Validate Username / Password on ESX(i) Host
A simple script to validate the login credentials against an ESX(i) host. Useful when validating that the credentials are what you think they should be.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 <# .
Posts
VMware PowerCLI 5 Cmdlets by Noun
Generated using this post.
<th> Verbs </th> <td> Get,New,Remove,Set </td> <td> Get,New,Remove </td> <td> Get,New,Remove </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,New,Remove,Set </td> <td> Get,Move,New,Remove,Set </td> <td> Get,New,Remove,Set </td> <td> New,Remove,Set </td> <td> Get,Move,New,Remove,Set </td> <td> Get,New,Remove,Set </td> <td> Get </td> <td> Copy </td> <td> Apply,Get </td> <td> Get,New,Remove,Set </td> <td> Get </td> <td> Get </td> <td> Get </td> <td> Get,New,Remove,Set </td> <td> Get,Move,New,Remove,Set </td> <td> Get </td> <td> Copy,Get,New,Remove,Set </td> <td> Get,Move,Remove </td> <td> Get,New,Remove,Set </td> <td> Get </td> <td> Get </td> <td> Get,New,Remove,Set </td> <td> Get,Set </td> <td> Get,New,Remove,Set </td> <td> Get,New,Remove,Set </td> <td> Add,Get,Remove </td> <td> Get,Set </td> <td> Get </td> <td> Get,Move,New,Remove,Set </td> <td> Get,New,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,New,Remove,Set </td> <td> Get </td> <td> Get,New,Remove,Set </td> <td> Get </td> <td> Get,Stop,Wait </td> <td> Get,Move,New,Remove,Set </td> <td> Dismount,Mount,Update,Wait </td> <td> Get,Remove </td> <td> Export,Get,Import,Move,New,Remove,Set,Start,Stop </td> <td> Get </td> <td> Get,New,Remove </td> <td> Get </td> <td> Get </td> <td> Get </td> <td> Get,New,Remove,Set </td> <td> Get </td> <td> Get,New,Remove </td> <td> Get,New,Remove,Set </td> <td> Get,New,Remove,Set </td> <td> Get,New,Remove,Set </td> <td> Connect,Disconnect </td> <td> Get,Move,New,Remove,Restart,Set,Start,Stop,Suspend </td> <td> Get,Restart,Shutdown,Suspend </td> <td> Copy </td> <td> Get,Set </td> <td> Get,New,Remove </td> <td> Add,Get,Move,Remove,Restart,Set,Start,Stop,Suspend </td> <td> Get,New,Remove,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get </td> <td> Get,Set </td> <td> Get </td> <td> Format,Get </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,New,Remove,Set </td> <td> Add,Get,Remove </td> <td> Get,Install </td> <td> Apply,Export,Get,Import,New,Remove,Set </td> <td> Test </td> <td> Get </td> <td> Get,New,Remove,Set </td> <td> Get,Restart,Set,Start,Stop </td> <td> Get,Set,Test </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Invoke </td> <td> Get,Set </td>
Posts
Simple XML output of a data object
I am doing some data collection using PowerShell and the output needs to be a simple XML document string.
The built in cmdlets do a great job when persisting data, but they produce some fairly complicated XML that provides more detail on object types than I can use.
Here is a single function to take a PSObject based data object and turn it into XML. I have also included a test function to show an example of building the data object.
Posts
Testing TCP Network Firewall Ports from ESXi
As we all transition to ESXi there are certain activities that we need to figure out a new way of doing. One item that comes up in new deployments is making sure that all of the ESXi –> firewall rules are defined correctly.
I do not believe that there is a way to do this from the SDK so its off to Tech Support Mode. Unfortunately there is no telnet, netcat, or other network tool that I typically use.
Posts
PowerShell Asynchronous Job Queueing
Here is some sample code to have a variable size work queue for asynchronous jobs in PowerShell. The sample code uses Start-Job, but it was written as a skeleton to be able to run multiple PowerCLI tasks at once.
The variable length is beneficial in case the work should be split up, but there is a chance of overwhelming the system if too many concurrent jobs are started at once.
Posts
Basic PowerShell Registry Value Helpers
Working with registry values in PowerShell can be a little cumbersome, so here are some example helpers that I am using to simplify some of my configuration scripts.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 Function Get-RegistryValue { param ( $key, $value ) (Get-ItemProperty -Path $key -Name $value).
Posts
VMware PowerCLI 4.1.1 Cmdlets by Noun
Generated using this post.
<th> Verbs </th> <td> Get,New,Remove,Set </td> <td> Get,New,Remove </td> <td> Get,New,Remove </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,New,Remove,Set </td> <td> Get,Move,New,Remove,Set </td> <td> Get,New,Remove,Set </td> <td> New,Remove,Set </td> <td> Get,Move,New,Remove,Set </td> <td> Get,New,Remove,Set </td> <td> Copy </td> <td> Apply,Get </td> <td> Get,New,Remove,Set </td> <td> Get </td> <td> Get </td> <td> Get </td> <td> Get,New,Remove,Set </td> <td> Get,Move,New,Remove,Set </td> <td> Get </td> <td> Copy,Get,New,Remove,Set </td> <td> Get,Move,Remove </td> <td> Get,New,Remove,Set </td> <td> Get </td> <td> Get </td> <td> Get,New,Remove,Set </td> <td> Get,Set </td> <td> Get,New,Remove,Set </td> <td> Get,New,Remove,Set </td> <td> Add,Get,Remove </td> <td> Get,Set </td> <td> Get </td> <td> Get,Move,New,Remove,Set </td> <td> Get,New,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,New,Remove,Set </td> <td> Get </td> <td> Get,New,Remove,Set </td> <td> Get </td> <td> Get,Stop,Wait </td> <td> Get,Move,New,Remove,Set </td> <td> Dismount,Mount,Update,Wait </td> <td> Get,Remove </td> <td> Export,Get,Import,New,Remove,Set,Start,Stop </td> <td> Get,New,Remove </td> <td> Get </td> <td> Get </td> <td> Get </td> <td> Get,New,Remove,Set </td> <td> Get </td> <td> New,Remove </td> <td> Get,New,Remove,Set </td> <td> Get,New,Remove,Set </td> <td> Get,New,Remove,Set </td> <td> Connect,Disconnect </td> <td> Get,Move,New,Remove,Restart,Set,Start,Stop,Suspend </td> <td> Get,Restart,Shutdown,Suspend </td> <td> Copy </td> <td> Get,Set </td> <td> Get,New,Remove </td> <td> Add,Get,Move,Remove,Restart,Set,Start,Stop,Suspend </td> <td> Get,New,Remove,Set </td> <td> Get,Set </td> <td> Get </td> <td> Get,Set </td> <td> Get </td> <td> Format,Get </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,New,Remove,Set </td> <td> Add,Get,Remove </td> <td> Get,Install </td> <td> Apply,Export,Get,Import,New,Remove,Set </td> <td> Test </td> <td> Get,New,Remove,Set </td> <td> Get,Restart,Set,Start,Stop </td> <td> Get,Set,Test </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Get,Set </td> <td> Invoke </td> <td> Get,Set </td>
Posts
Quick and dirty PowerPath/VE output parser
Here is a quick and dirty PowerShell script to parse the output of the rpowermt command used to manage PowerPath/VE on ESX (for EMC arrays). I wrote the code quickly to solve a particular problem, but if I get requests I could extend it to parse the rest of the output and do so in a little more robust fashion.
Why do this? I am in the middle of migrations between frames and I needed an easy way to determine what needed moved when the storage admin said move all LUNs from CLARiiON XXXX to the new LUNs on YYYY – and make sure to move LUN 41 to LUN 88.
Posts
VMware PowerShell Get-VIHumanReadablePath
An example of how to get the human readable path of an object in the VMware SDK. This is using PowerShell and requires that PowerCLI be installed, but should be easily converted to other languages.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 Function Get-VIHumanReadablePath { param ( $target ) try { if ($target.
Posts
Running PowerShell in VMware Orchestrator – updated
Updated 7/29/2010 – I have added a new follow up post this post regarding another related hanging issue. Please make sure to check it out.
This is a copy of my comment in the VMware Communities, but some times the Google search results for items in this blog show up and the ones for the communities do not.
The original problem is that PowerShell scripts hang when running them in Orchestrator.
Posts
PowerCLI Examples for VMUG Presentation 7/20/2010
These are some examples that I will be reviewing at an upcoming Central Ohio VMware User’s Group.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 # List all VMs Get-VM # Get one VM Get-VM ubuntu01 # Get VMs that match Get-VM ubuntu* # List VMs in a Datacenter Get-Datacenter dc001 | Get-VM # List VMs in a cluster Get-Cluster cluster001 | Get-VM # Get 2 CPU or larger VMs Get-VM | Where-Object {$_.
Posts
Export and Import Customization Specs Using PowerCLI
Here are a couple of functions to help you export and import OS customization specs in vCenter. Be aware that if you do this between vCenters or the certificate changes then you will have to set any encrypted passwords to their correct value after the import.
These functions and the standard *-OSCustomizationSpec cmdlets should allow you to replicate your customization specs between multiple vCenters fairly easily.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 Function Export-OSCustomizationSpec { param ( [string]$specName, [string]$exportFile = "$specname.
Posts
Notify All Active vSphere Users (PowerCLI version)
Steve Jin recently posted How to Notify All the Active vSphere Users on his DoubleCloud blog. Below are some functions to make this easy to do via PowerCLI.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Function Get-VIServiceMessage { $sessionManager = Get-View SessionManager $sessionManager.Message } Function Set-VIServiceMessage { param ( [String]$message = $(throw "Must specify a message.") ) $sessionManager = Get-View SessionManager $sessionManager.
Posts
Summarize PowerCLI Cmdlets by Noun
Here is some simple code to generate a reference list of the PowerCLI cmdlet objects(nouns) and what actions(verbs) you can perform on them.
This can come in handy for people new to PowerCLI to show them what the cmdlets will handle for them.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 $commandTable = @{} $commandList = Get-Command -Module VMware.VimAutomation.Core -CommandType Cmdlet foreach ($command in $commandList) { if (!
Posts
Bulk password change on ESX hosts
Here is an script to make life a little easier when doing bulk updates to a password for an account as long as the account has a common password on the different hosts.
The script has some documentation in it so make sure to use Get-Help to find more detail.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 Get-Help .
Posts
PowerShell advanced parameter behavior unexpected
I have been experimenting with parameter values from the pipeline and the processing behavior is slightly different when using piplines vs. parameterized values. It is easy enough to work around, but I wanted to make sure and explain the issue and one workaround.
The standard way of using a pipeline parameter is to do something like this:
param ( [parameter(Mandatory=$true, ValueFromPipeLine=$true)] [String[]]$item ) In cases where you accept input from the pipeline or a single item as an input parameter this works fine.
Posts
List VMs with Non Thick Disks
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 foreach ($vm in Get-VM) { $badFormat = $false foreach ($hardDisk in (Get-HardDisk -VM $vm)) { if ($hardDisk.StorageFormat -ne "Thick") { $badFormat = $true } } if ($badFormat) { $vm.Name } }
Posts
Determine VMs in a SRM recovery plan using PowerShell
Here is some PowerShell code to determine the VMs that are in a VMware Site Recovery Manager recovery plan.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 #requires -version 2 # Description: List the VMs in a SRM recovery plan.
Posts
Set-VMHostService Policy Parameter
Here are the possible values for the policy parameter on Set-VMHostService and their corresponding value in the VI client.
<th> VI Client Value</ht></tr> <tr> <td> automatic </td> <td> Start automatically if any ports are open… </td> <tr> <td> on </td> <td> Start and stop with host </td> <tr> <td> off </td> <td> Start and stop manually </td></table>
Posts
Require a minimum version of PowerCLI
A lot of the script that I have been writing rely on new cmdlets or properties in the current release of PowerCLI. Telling people to upgrade before running the scripts has not been enough so I am going to do the smart thing and check that the appropriate version is running.
Here is the code to that I am using to do the validation.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 # By default this will check that the running version of PowerCLI is greater # than or equal to the specified version and throw an exception if not.
Posts
VMware vCLI “persistent login”
Here is a short convenience script that will simulate a persistent login to a VMware host system when using the vCLI on Windows. Typically you have to specify a lot of parameters that include login information or a session file. With this method you just run the script and provide the hostname, username, and password for the connection.
After running this script you can run commands like “vicfg-mpath.pl –list” without additional parameters.
Posts
VMware PowerCLI and Get-View filters
I have been confused by how to best use the -filter parameter on Get-View so I decided to dig around a little. The examples that are given always seem to be (semi)exact matches and I wanted to do an OR in my filter. Per the help this did not appear possible, but after some digging I found that it is possible for a single property at least.
The help has this to say about the Filter parameter:
Posts
PowerShell and SRM – Basic Logic
Here is a script that shows how to get access to the environment variables that VMware sets for a command step and perform some basic control flow using them.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 # A starter script for examining the VMware environment variables and # performing some logic steps relating to the SRM workflow.
Posts
Using PowerShell in VMware Site Recovery Manager
This is the first post in a series about using PowerShell to automate steps in a VMware Site Recovery Manager (SRM) workflow. I will be posting bits and pieces as I learn more and if everything works the way I would like I will post an overview of my testing and recovery procedure.
To use PowerShell in a Command Step of a recovery plan you will need to do the following:
Posts
Maximum vSwitches in vSphere
There appears to be a discrepancy in the VMware documentation regarding the maximum number of vSwitches. The Configuration Maximums document states that the limit is 248. The configuration guide lists the maximum as 127 which is what it was in 3.5. I am not sure if I misunderstand what they mean by “Standard switches per host 248”. If you see the error of my ways let me know.
Here is some code that I used to see how many vSwitches I could put on a host.
Posts
Configure NTP on Multiple Hosts Using PowerShell
A handy script to correct NTP settings on multiple hosts.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 #Usage: Get-VMHost | .\ConfigureNtpServer.ps1 BEGIN { $ntpServers = @("ntpserver01","ntpserver02") $hostDateTimeConfig = New-Object Vmware.Vim.HostDateTimeConfig $hostNtpConfig = New-Object VMware.Vim.HostNtpConfig $hostDateTimeConfig.ntpConfig = $hostNtpConfig $hostDateTimeConfig.ntpConfig.server = $ntpServers } PROCESS { $vmHost = $_ $vmHostView = Get-View $vmHost.ID $dateTimeSystem = $vmHostView.ConfigManager.DateTimeSystem $DateTimeSystemRef = Get-View $dateTimeSystem $DateTimeSystemRef.
Posts
Gzip creation in PowerShell – Gzip-FileSimple.ps1
I have a need to compress some of the data I am exporting using PowerShell so I figured why not use PowerShell to do it? I did not want to have a dependency on the Community Extensions even though they have solved this problem already. Luckily in newer versions of .Net there is the System.IO.Compression class.
Here is my code which is based off of the Microsoft example for the class.
Posts
PyOhio 2009
I just finished attending my first PyOhio and I have to say that I enjoyed it. It was interesting to see so many people involved enough in their interests to spend a weekend talking about code. There were sessions geared to all levels of Python knowledge and a wealth of knowledge to be shared.
I am a Python novice so my ability to hang in on the deeper side discussions was limited, but I came away with much more information and a bunch of areas to dig into deeper.
Posts
Get-VmDiskPersistenceReport
As part of our auditing process I need validate guest disk persistence settings. Here is a simple snippet to get the needed data.
1 2 3 4 Get-VM | ForEach-Object { $vmname = $_.Name $_.HardDisks | Select-Object @{Name="VM"; Expression={$vmname}}, Filename, Persistence }
Posts
Free PowerShell eBook
As reported on the PowerShell Team blog.
Free PowerShell V1 Book From the Makers of PowerShell Plushttp://blogs.msdn.com/powershell/archive/2009/07/17/free-powershell-v1-book-from-the-makers-of-powershell-plus.aspx
Posts
Get-PreviousWeekdayDate
I am fleshing out my automated monitoring/reporting system and I wanted to include some performance data exports. As part of this I always wanted my weekly exports to start on a certain day of the week no matter when the script was run. I also needed to make sure that I received a weeks worth of data.
To help out I wrote this function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 # Find the date of a previous weekday.
Posts
Report on HA Isolation Response
1 2 3 4 5 6 7 8 9 10 $desiredResponse = "DoNothing" foreach ($cluster in Get-Cluster) { $result = $cluster | Select-Object Name, HAIsolationResponse, @{Name="DesiredResponse"; Expression={$desiredResponse}} if (!$cluster.HAEnabled) { $result.HAIsolationResponse = "HaNotConfigured" } $result }
Posts
LoadVMs-FromFile
I was using the VMware VI Toolkit for Windows for a change and I needed to load VMs from a CSV and my typical stream oriented way of doing this was very inefficient over the WAN (or LAN really). There are many ways of making Get-VM operations faster, but for this change I decided to use the standard Get-VM cmdlet with an array of computer names instead of doing them one by one.
Posts
Secure Credential Storage
I have added some code to my Scripts/Programs page for securely storing credentials to disk to be used by scripts at a later time.
I explored the VI Credential cmdlets and I was not 100% happy with them so I decided to implement my own version that uses the Microsoft DPAPI for encryption. Make sure to look at the README as it covers usage and current limitations.
I wrote these for use in some automated VMware monitoring I am doing, but there is no reason they have to be used with the VI Toolkit.
Posts
Issue with Read-Host PowerShell 2 CTP3
When using Read-Host with the AsSecureString paramater in PS2 CTP3 the prompt text does not appear. Here is a wrapper function that simulates the basic behavior. This does not implement all of the other parameters of Read-Host as I only needed it for the base case.
1 2 3 4 5 6 7 8 9 # PowerShell v1 Read-Host "blah" -AsSecureString blah: **** System.Security.SecureString # Powershell v2 CTP3 Read-Host "blah" -AsSecureString **** System.
Posts
My Favorite Scripting Editors
Notepad++
I use Notepad++ for quick editing jobs because it is a very capable editor and it has a quick load time. Works on a thumb drive.
Komodo Edit (Komodo IDE)
I use Komodo Edit a lot when I am working with Python, Perl, VBScript, JScript, or XML files. It works on my Linux system as well which is a great bonus. I like this editor because it more of a development environment and gives me a lot of flexibility in configuration and custom tools.
Posts
VI SDK – Beware cached data and assumptions
Applications often cache data and that is good because that generally makes them perform better for users. However, if you make assumptions that what you see is the absolute truth you can run into trouble.
1 2 3 4 5 6 7 8 9 Connect-ViServer myVirtualCenter001 # Let's check the status of the server to make sure I can go home. (Get-vmhost myVmHost001.local | Get-View).OverallStatus green #Looks good. Well, maybe not.
Posts
Validating VM advanced settings
Now that we have covered how to make advanced settings changes we need to validate that the settings have been applied. Assuming that a script or command worked is never as good as checking it. Below is a script to do just that.
The script lists all statuses so if you only want to see issues you can pipe the output into the Where-Object cmdlet like so:
<vmObject(s)> | .\Validate-VmAdvancedSettings.ps1 | Where-Object {$_.
Posts
Making advanced settings changes to a running VM
If you use a method like that in the Powershell script I posted the changes can be made to a running VM. This is great because that dialog box is disabled in Virtual Center when the vm is up.
The settings do not take effect until the VM is power cycled (not just restarted in the OS). This is not that big of a deal on clusters with VMotion licensed because a VMotion starts a new instance of the VM on the destination host.
Posts
Get-AllRolePrivileges
This is a good script to easily report on privileges and can easily be extended to audit against a known good list of expected roles/privileges.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 # Must already be connected to a viserver. This works on the default vi server. $si = Get-View ServiceInstance $am = Get-View ($si.Content.AuthorizationManager) $roles = $am.RoleList foreach ($role in $roles) { foreach ($privilege in $role.
Posts
Script to update tools in templates.
Here is a script that takes template objects and updates their VMware tools.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 # Usage: <template object(s)> | .\Upgrade-ToolsTemplate.ps1 # Example: Get-Template template1 | .\Upgrade-ToolsTemplate.ps1 # Get-Datacenter corporate | Get-Template | .
Posts
Get-VIAllPrivileges
This is a good script to easily report on privileges and can easily be extended to audit against a known good list of expected roles/priveleges.
1 2 3 4 5 6 7 8 9 10 11 12 #Must already be connected to a viserver. This works on the default vi server. $si = Get-View ServiceInstance $am = Get-View ($si.Content.AuthorizationManager) foreach ($role in $am.RoleList) { foreach ($privilege in $role.Privilege) { $role| Select-Object RoleId, System, Name, @{Name="Privilege"; Expression={$privilege}} } }
Posts
VI Toolkit Install Script – PowerShell
Here is a script I wrote to install the VI Toolkit Extensions on my systems. The VITKE team decided to go with a cmd file in case PowerShell was not installed and I think that makes perfect sense. I am posting this code just in case it will be useful to someone else.
InstallVitkEextensions.ps1
Posts
Forwarding VMware logs to a syslog server using PowerShell
I am working on a PowerShell script to replace the functionality of the logging daemon in VIMA and am making some progress. Check out the scripts/programs page for updates. I have posted the code out there for sending syslog messages from PowerShell. There are some third party tools for this but I wanted the learning experience and I am cheap.
Posts
PowerShell: Custom Objects with Method Parameters
I was not sure how to add parameters to custom object methods, but it is pretty simple. Here is a simple example.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Function CustomObjectWithMethodParameter { $CustomObject = New-Object PSObject $CustomObject | Add-Member -MemberType ScriptMethod -Name testParam -Value { param ( [String]$parameter01 = $(throw "parameter01 must be specified.") ) Write-Host "Parameter01 value: $parameter01" } $CustomObject } $myobj = CustomObjectWithMethodParameter $myobj.
Posts
PowerShell: Get VMs running on a single host
I wanted to perform an action on all of the VMs on a particular host, but using my connection to Virtual Center instead of reconnecting directly to the host. I found something interesting.
This is wrong:
Get-VMhost esx1.local | Get-VM #Not what I expected. This does not work as I expected. It gets all of the VMs in the cluster instead of just the ones registered with the host. My best guess is that this is because the host is not really a container object when in a cluster.
Posts
PowerShell ISE Custom Menu
Here is some code that I am working on for customizing the PowerShell ISE to do some things that I would like it to do.
`Update 1/22/2009: After switching to a full WordPress install I don’t have a problem uploading code files any more. Keep any eye on this pagefor any updates to the custom ISE menu. Feedback is welcomed.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 # # Add Run with arguments capability # $psise.