VMware Cloud Community
tonygent
Enthusiast
Enthusiast
Jump to solution

Code format in examples

As a complete Newb to the whole powershell scripting element, I'm deeeeply confused by the lack of clarity with the code snippets often shown.

Once downloading a snippet of code from the forums or the VMware examples pages, I then have to spend 30 mins 'deciphering' the code to figure out where the carridge returns are surposed to go? And often when the code is 'actually doing'

For some reason, all the code in the little boxes does not state when a new line is required. A good example would be :

Get-Cluster -Name | Get-VMHost -State "Connected" | %{ $esx = Get-View $_.ID $optmgrMoRef = $esx.configManager.advancedOption $optmgr = Get-View $optmgrMoRef $optarray = $optmgr.QueryOptions("LVM.Enableresignature") $optarray[0].Value = 1 $optmgr.UpdateOptions($optarray) }

This code, found on the forums here, just does not work if patsted into notepad and run! I believe there should be a selection of new lines starting at the creation of the variables. But for those of use not yet familiar with the structure if the code it takes ages to figure this out. Below is my deciphered element of the same code :

Connect-VIServer $strVC

$oCluster = Get-Cluster -name $strCLUSTER

write-host $oCluster

$oHosts = $oCluster | Get-VMHost -state "Connected"

Foreach ($ohost in $oHosts)

{

Echo $oHost.Name

$esx = Get-View $oHost.ID

$optmgrMoRef = $esx.configManager.advancedOption

$optmgr = Get-View $optmgrMoRef

$optarray = $optmgr.QueryOptions("LVM.Enableresignature")

$optarray[0].Value = 1

$optmgr.UpdateOptions($optarray)

}

A lot of the code I've tried to download from these forums just does not work unless it's 're-jigged' with new line spaces. Is this a problem with my browser - or are others having the same issue??

I'm using notepad.exe as my main scripting app - is there another app I should be using that perhaps makes these changes for me?

Any advise would be much appreciated.

TG

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Hi Tony, welcome to the VITK community.

The newline problem is a problem with the forum SW in combination with an IE browser.

When you use a FF browser the problem doesn't seem to be there.

On the ThinDownload site you can find a (standalone) FF browser.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
5 Replies
LucD
Leadership
Leadership
Jump to solution

Hi Tony, welcome to the VITK community.

The newline problem is a problem with the forum SW in combination with an IE browser.

When you use a FF browser the problem doesn't seem to be there.

On the ThinDownload site you can find a (standalone) FF browser.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
tonygent
Enthusiast
Enthusiast
Jump to solution

Hi LucD

Well spotted - have tried with FireFox3 and it seems to be much better formatted!!

Also - I was actually using Google Chrome not IE, So Chrome must have the same issue. Guess I'm going back to FireFox in the short term! :oD

Thanks for the swift reply.

Can you recommend a free GUI for writing PS code - or am I better off with notepad??

TG

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Glad to have helped.

That means I won't be testing Chrome in the coming days Smiley Wink

Both editors I'm using for PS are not free Smiley Sad

PowerShellPlus used to be free for personal use but the new version is currently priced at $145.

You just missed the September offer where it was priced at $79.

The other I use is Admin Script Editor. That one has a nice Form design tool and several wizards.

Both are, in my opinion, well worth the money.

Perhaps others know of some free GUI editors that support PS ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
halr9000
Commander
Commander
Jump to solution

The best free editor for posh is PowerGUI.

OT: I'm using and loving Chrome--except for the line break issue. Smiley Sad






Author of the upcoming book: Managing VMware Infrastructure with PowerShell

Co-Host, PowerScripting Podcast (http://powerscripting.net)

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
Reply
0 Kudos
tonygent
Enthusiast
Enthusiast
Jump to solution

Me 2 Hal,

Has to be said - Chrome is really good. Fasters browser by some margin and just so easy to use. Apart from this issue am struggling to fault it!!

TG

Reply
0 Kudos