TechProsaic
(powershell & other stuff)
2012-1
28

And Now, for Something Completely Different!

In:General by halr9000
Tags: Splunk

spacer I am very happy to announce that I’ve taken a new job with Splunk! I’m going to be a Solutions Architect working in their Business Development Partner Application Development team for my buddy Brandon Shell. As a part of my new role, I will be using Python (and PowerShell wherever I can fit it in) to help to create solutions around our areas of focus. There will be VMware stuff for sure, and some other cool technologies as well that I’m very interested in. More news as I figure out what they are. spacer

The job is 100% working from home, which is awesome. I’m glad to get back to that after several years of braving Atlanta traffic. (I had worked for HP from home for a while.) You know what else is great about this new job? I won’t be on call 24×7! Very glad to ditch the pager! (Not to say that I won’t return your calls, Brandon. spacer , just not while I am asleep.)

I’m all set to start Feb 13th!

CrunchBase Information

Splunk
Information provided by CrunchBase

10 Comments
2011-12
23

PowerShell Workflow, defined (V3 CTP2)

In:Powershell by halr9000
Tags: CTP2,pre-release,V3
spacer

A workflow is a sequence of automated steps or activities that execute tasks on or retrieve data from one or more managed nodes (computers or devices). These activities can include individual commands or scripts. Windows PowerShell Workflow enables, IT pros and developers alike, to author sequences of multi-computer management activities — that are either long-running, repeatable, frequent, parallelizable, interruptible, stoppable, or restartable — as workflows. By design, workflows can be resumed from an intentional or accidental suspension or interruption, such as a network outage, a reboot or power loss.

I just had to paste this paragraph. It comes from the recently published “Getting Started with PowerShell Workflow” as announced in this post on the PowerShell team blog. You can grab the PDF from the WMF3 CTP2 download page.

Hot stuff! Go grab the 14 page doc so you can be ready for when v3 ships! There are a ton of examples so that you get started quickly.

Disclaimer: this is pre-release code and will definitely change

Only 1 comment
2011-10
21

PowerShell Tip: Don’t forget the type!

In:Powershell by halr9000
Tags: tips
spacer

So I’m sitting here building a bunch of virtual machines using PowerCLI. I decided to start with a spreadsheet into which I’ve collected many of the important things about a virtual machine:

spacer

Since I don’t actually build VMs every day, and I haven’t focused on a build process (like I should, I know!) yet, this spreadsheet was a first draft of a build process and it was made for humans, not machines. What does this mean? Well, obviously, by looking at the Memory column, any of you would guess that the unit of measurement is gigabytes. However, VMware happens to measure memory in megabytes.

Long story short, I wrote a quick one-liner in PowerShell to “spec out” the newly-cloned virtual machines using this spreadsheet. As I said, it’s not a build process yet, but it will be when I’m done. Baby steps. The one-liner looks like this ($t is the variable that holds the data obtained from the spreadsheet, using a simple Import-Csv cmdlet):

   1: $t | % { Set-VM -VM $_.name -NumCpu $_.cpu -MemoryMB $_.Memory }

Once I started that running, I quickly realized that 8MB VMs would do me no good. spacer So, I amended my script to this:

   1: $t | % { Set-VM -VM $_.name -NumCpu $_.cpu -MemoryMB ( $_.Memory * 1024 ) }

That’s when I got a really weird error:

Set-VM : Cannot bind parameter ‘MemoryMB’. Cannot convert value "888888888888888888888888888888888888888888888888888888

88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888

88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888

88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888

88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888

88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888

88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888

88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888

88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888

888888888888888888" to type "System.Int64". Error: "Value was either too large or too small for an Int64."

Yuck! That one threw me for a loop for a moment until I realized the important lesson of the day. When you use a technique like Import-Csv, the resulting object is a bunch of strings! What happens when you multiply a string by a number in PowerShell? Yes, it’s effectively a concatenation. So in my case, the number 8 followed by one-thousand-and-twenty-three of the same. Nice, when that’s what you intended. That was not my intent this time!

So to round this post out with a fix, here’s the right way to get the intended result, which was to turn “8” into “8192”:

   1: $t | % { Set-VM -VM $_.name -NumCpu $_.cpu -MemoryMB ( [int]$_.Memory * 1024 ) }

Note the “[int]” there before the $_. That will convert the resulting property to an integer BEFORE performing the multiplication. That’s the key here, it has to happen before (in the order of precedence), otherwise I end up with a bunch of 8’s. Now, I happen to know the order of operator precedence in PowerShell well enough to know that the above would work without any doubt, but if you aren’t sure about a particular piece of code, you can always surround a portion of a statement with parentheses in order to ensure that you get the order that you need.

2 Comments
2011-8
25

PowerCLI v5 is available today, download it NOW!

In:PowerCLI, Powershell, VMware by halr9000
Tags: vsphere
spacer

Run, don’t walk to vmware.com/go/powercli to grab the latest version of the world’s best PowerShell snapin. That’s right, v5 is out and you can grab it now! And the coolest part is that while nobody will have vSphere 5 in production on day one (ok, there’s a couple of you out there), PowerCLI v5 is a client-based tool with no dependencies, and it’s downwards-compatible! There is literally no reason for you not to upgrade right this instant! I am using exclamations here, people!

I’ve had beta builds installed for some time, but I didn’t want to do blog posts based on pre-release builds for fear that things would change. Now that it’s out, I’ll start pushing out some posts about what’s new and all that, so stay tuned. For now, some quick stats and info:

There are now FOUR VMware snap-ins installed with PowerCLI v5:

PowerCLI U:\> Get-PSSnapin vmware*

Name        : VMware.VimAutomation.Core
PSVersion   : 2.0
Description : This Windows PowerShell snap-in contains Windows PowerShell cmdlets for managing vSphere.

Name        : VMware.VimAutomation.License
PSVersion   : 2.0
Description : This Windows Powershell snap-in contains cmdlets for managing License components.

Name        : VMware.DeployAutomation
PSVersion   : 2.0
Description : Cmdlets for Rule-Based-Deployment

Name        : VMware.ImageBuilder
PSVersion   : 2.0
Description : This Windows PowerShell snap-in contains VMware ESXi Image Builder cmdlets used to generate custom images.

There are 293 cmdlets in total across these snap-ins. Here they are, grouped by Noun and Verb:

PowerCLI U:\> $c = Get-Command -Module vmware*
PowerCLI U:\> $c.Length
293
PowerCLI U:\> $c | group verb

Count Name                      Group
—– —-                      —–
    6 Add                       {Add-DeployRule, Add-EsxSoftwareDepot, Add-E…
    3 Apply                     {Apply-DrsRecommendation, Apply-ESXImageProf…
    1 Compare                   {Compare-EsxImageProfile}
    1 Connect                   {Connect-VIServer}
    4 Copy                      {Copy-DatastoreItem, Copy-DeployRule, Copy-H…
    1 Disconnect                {Disconnect-VIServer}
    1 Dismount                  {Dismount-Tools}
    3 Export                    {Export-EsxImageProfile, Export-VApp, Export…
    1 Format                    {Format-VMHostDiskPartition}
   95 Get                       {Get-AdvancedSetting, Get-AlarmAction, Get-A…
    2 Import                    {Import-VApp, Import-VMHostProfile}
    1 Install                   {Install-VMHostPatch}
    1 Invoke                    {Invoke-VMScript}
    1 Mount                     {Mount-Tools}
    9 Move                      {Move-Cluster, Move-Datacenter, Move-Folder,…
   37 New                       {New-AdvancedSetting, New-AlarmAction, New-A…
   42 Remove                    {Remove-AdvancedSetting, Remove-AlarmAction,…
    2 Repair                    {Repair-DeployImageCache, Repair-DeployRuleS…
    4 Restart                   {Restart-VM, Restart-VMGuest, Restart-VMHost…
   58 Set                       {Set-AdvancedSetting, Set-AlarmDefinition, S…
    1 Shutdown                  {Shutdown-VMGuest}
    4 Start                     {Start-VApp, Start-VM, Start-VMHost, Start-V…
    5 Stop                      {Stop-Task, Stop-VApp, Stop-VM, Stop-VMHost…}
    3 Suspend                   {Suspend-VM, Suspend-VMGuest, Suspend-VMHost}
    1 Switch                    {Switch-ActiveDeployRuleSet}
    3 Test                      {Test-DeployRuleSetCompliance, Test-VMHostPr…
    1 Update                    {Update-Tools}
    2 Wait                      {Wait-Task, Wait-Tools}

PowerCLI U:\> $c | group noun

Count Name                      Group
—– —-                      —–
    6 DeployRule                {Add-DeployRule, Copy-DeployRule, Get-Deploy…
    2 EsxSoftwareDepot          {Add-EsxSoftwareDepot, Remove-EsxSoftwareDepot}
    3 EsxSoftwarePackage        {Add-EsxSoftwarePackage, Get-EsxSoftwarePack…
    3 PassthroughDevice         {Add-PassthroughDevice, Get-PassthroughDevic…
    9 VMHost                    {Add-VMHost, Get-VMHost, Move-VMHost, Remove…
    3 VmHostNtpServer           {Add-VmHostNtpServer, Get-VMHostNtpServer, R…
    2 DrsRecommendation         {Apply-DrsRecommendation, Get-DrsRecommendat…
    6 ESXImageProfile           {Apply-ESXImageProfile, Compare-EsxImageProf…
    7 VMHostProfile             {Apply-VMHostProfile, Export-VMHostProfile, …
    2 VIServer                  {Connect-VIServer, Disconnect-VIServer}
    1 DatastoreItem             {Copy-DatastoreItem}
    5 HardDisk                  {Copy-HardDisk, Get-HardDisk, New-HardDisk, …
    1 VMGuestFile               {Copy-VMGuestFile}
    4 Tools                     {Dismount-Tools, Mount-Tools, Update-Tools, …
    9 VApp                      {Export-VApp, Get-VApp, Import-VApp, Move-VA…
    2 VMHostDiskPartition       {Format-VMHostDiskPartition, Get-VMHostDiskP…
    4 AdvancedSetting           {Get-AdvancedSetting, New-AdvancedSetting, R…
    3 AlarmAction               {Get-AlarmAction, New-AlarmAction, Remove-Al…
    3 AlarmActionTrigger        {Get-AlarmActionTrigger, New-AlarmActionTrig…
    2 AlarmDefinition           {Get-AlarmDefinition, Set-AlarmDefinition}
    2 Annotation                {Get-Annotation, Set-Annotation}
    4 CDDrive                   {Get-CDDrive, New-CDDrive, Remove-CDDrive, S…
    5 Cluster                   {Get-Cluster, Move-Cluster, New-Cluster, Rem…
    4 CustomAttribute           {Get-CustomAttribute, New-CustomAttribute, R…
    5 Datacenter                {Get-Datacenter, Move-Datacenter, New-Datace…
    4 Datastore                 {Get-Datastore, New-Datastore, Remove-Datast…
    1 DatastoreCluster          {Get-DatastoreCluster}
    2 DeployRuleSet             {Get-DeployRuleSet, Set-DeployRuleSet}
    4 DrsRule                   {Get-DrsRule, New-DrsRule, Remove-DrsRule, S…
    1 ErrorReport               {Get-ErrorReport}
    1 EsxCli                    {Get-EsxCli}
    1 EsxSoftwareChannel        {Get-EsxSoftwareChannel}
    1 EsxTop                    {Get-EsxTop}
    4 FloppyDrive               {Get-FloppyDrive, New-FloppyDrive, Remove-Fl…
    5 Folder                    {Get-Folder, Move-Folder, New-Folder, Remove…
    1 HAPrimaryVMHost           {Get-HAPrimaryVMHost}
    3 Inventory                 {Get-Inventory, Move-Inventory, Remove-Inven…
    4 IScsiHbaTarget            {Get-IScsiHbaTarget, New-IScsiHbaTarget, Rem…
    1 LicenseDataManager        {Get-LicenseDataManager}
    1 Log                       {Get-Log}
    1 LogType                   {Get-LogType}
    4 NetworkAdapter            {Get-NetworkAdapter, New-NetworkAdapter, Rem…
    2 NicTeamingPolicy          {Get-NicTeamingPolicy, Set-NicTeamingPolicy}
    4 OSCustomizationNicMapping {Get-OSCustomizationNicMapping, New-OSCustom…
    4 OSCustomizationSpec       {Get-OSCustomizationSpec, New-OSCustomizatio…
    2 PowerCLIConfiguration     {Get-PowerCLIConfiguration, Set-PowerCLIConf…
    1 PowerCLIVersion           {Get-PowerCLIVersion}
    5 ResourcePool              {Get-ResourcePool, Move-ResourcePool, New-Re…
    3 ScsiController            {Get-ScsiController, New-ScsiController, Set…
    2 ScsiLun                   {Get-ScsiLun, Set-ScsiLun}
    2 ScsiLunPath               {Get-ScsiLunPath, Set-ScsiLunPath}
    4 Snapshot                  {Get-Snapshot, New-Snapshot, Remove-Snapshot…
    1 Stat                      {Get-Stat}
    4 StatInterval              {Get-StatInterval, New-StatInterval, Remove-…
    1 StatType                  {Get-StatType}
    3 Task                      {Get-Task, Stop-Task, Wait-Task}
    5 Template                  {Get-Template, Move-Template, New-Template, …
    2 UsbDevice                 {Get-UsbDevice, Remove-UsbDevice}
    1 VIAccount                 {Get-VIAccount}
    3 VICredentialStoreItem     {Get-VICredentialStoreItem, New-VICredential…
    1 VIEvent                   {Get-VIEvent}
    1 View                      {Get-View}
    1 VIObjectByVIView          {Get-VIObjectByVIView}
    4 VIPermission              {Get-VIPermission, New-VIPermission, Remove-…
    1 VIPrivilege               {Get-VIPrivilege}
    3 VIProperty               

gipoco.com is neither affiliated with the authors of this page nor responsible for its contents. This is a safe-cache copy of the original web site.