• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

PowerShell 2.0 or 3.0?

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

g0dM@n

Inactive Moderator
Joined
Sep 27, 2003
So I'm a VMware administrator at work. I design the entire front-end (desktop side) of it. I am cleared to take a 5-day class on PowerShell, and was wondering which is more beneficial: 2.0 or 3.0

Any advice?
 
The newest one, of course :) There's no reason to run an old PowerShell.

EDIT: Misread 2008 vs 2005. Only 2.0 works on XP, but really, how much longer are companies going to hold on to XP?
 
The newest one, of course :) There's no reason to run an old PowerShell.

EDIT: Misread 2008 vs 2005. Only 2.0 works on XP, but really, how much longer are companies going to hold on to XP?

Well, they still offer 2.0, and I wondered why it would still be offered, probably b/c of what you said. So... most of our VMs here are still XP, but we are pushing for Windows 7 linked-clones, or Windows 7 persistent at the very least. I could use 2.0 to assist with our current XP environment, but then would miss out on 3.0. It's definitely a personal decision, but I wanted to see what others say.

*EDIT*
I DIDN'T EVEN NOTICE... There is also Version 4.0.
 
Last edited:
I DIDN'T EVEN NOTICE... There is also Version 4.0.

Some of the things I read mention the 4.0 preview at least is not supported on Windows 8 (but didn't say whether that would apply to the final release), and would only work on 7 SP1+ and 8.1+. Odd choice, there.
 
Some of the things I read mention the 4.0 preview at least is not supported on Windows 8 (but didn't say whether that would apply to the final release), and would only work on 7 SP1+ and 8.1+. Odd choice, there.

I just registered for 3.0. I hope I made the right choice!! :)

This will be my first programming class since college!! It's been about 12 years since I took Visual Basic and C++... I'd be lucky to remember 2 things. It's okay, though, logic/math were my skillset anyway. I hope I won't be too rusty going in...
 
3.0 has some nice improvements over 2.0 where virtual machines are concerned and where accessing remote shared drives are concerned as well.

In addition to the class, pick up the Windows PowerShell Cookbook. It's geared towards tasks that Admins do so it should help you out.

Also, Powershell.org is a great site to check out.
 
Hopefully you find the class to be helpful. I've been toying with PowerShell more and more myself as of late. It's really amazing what all you can do with PS. I'm currently making use of it for work related tasks. Right now, I'm just using Google to figure out how to do everything and it's working out alright but I'd love to take a class soon. I'm working in Web Hosting again and it's making site setups a breeze for our operations team :)

I used to support our VMware View 4.0 & 4.5 environments and we had everything done with PowerShell in the way of cloning a VM from our master template, applying basic customizations/updates to the new parent VM and then re-sealing the PVM/TVM for use in a new pool once ready. It made it sooooo much easier to work with. PowerCLI was a life saver, that's for sure! I can't even imagine how many hours/days it saved me from having to manually perform all of those commands manually.
 
Looks like you've already made your decision, but my answer would be definitely go with 3.0. Don't get me wrong, 2.0 is extremely powerful, but 3.0 adds a lot of functionality, as well as simplifies a lot of things down to a couple lines of code that would otherwise take a dozen in PS 2.0.

Most of the sysadmin work that I do is on AIX, but it's nice to be able to use Powershell rather than VBS or batch to do some fairly simple (or complex) things on the few Windows servers that I manage, as well. My only complaint is the lack of a good IDE for it. When you have the power of .NET at your fingertips, you come to expect intellisense! You never really realize how much you appreciate it until you're writing .NET code in Notepad++ or something.

Beyond the professional applications for Powershell, it can make personal tasks much easier, too. Recently I wrote a web scraper that pulls all the clearance and open box items from my local Best Buy's store, and I can filter and sort by price, % off, etc. Recently I picked up a nice laptop (i5, 6gb ram, 750gb hadd, 15.4") for the wife for $250. Also snagged 2x 22" LG LED monitors for $37.50 each, brand new in box. (Though this was from Office Depot, did the same thing for it). :thup:

In my spare time, I also run a dedicated server that I run 12 CS:S/CS:GO servers on. We were getting several thousand of failed login attempts via RDP per hour.. so I wrote a PS script to monitor eventlog, and blacklist any IP that had more than 5 failed login attempts in a minute, and add it to a rule on the firewall.

Needless to say, I'm a huge advocate for Powershell!:attn:
 
Wow, after reading your posts, I'm even more excited; not to mention, work pays me even while I'm at class, it's only 7 hours a day (as opposed to 9 at work), and it's at least 90 min less of a commute per day. :) It will be an awesome week... learning, and having more time on my hands. I wish I could get paid to learn more than just one week a year. :)

notarat, I will look into the cookbook.

MB, VMware is exactly why I want it!

PCG4L, share that tool for BB now!! :)
 
Sure thing. Looking at other people's code and diving in head first is the way I learn best. Reading books can only get me so far.

Invoke-WebRequest requires PS 3.0.. in 2.0 you had to instantiate a web browser to accomplish the same thing.. much more convoluted that way.
This is a quick and dirty way to do it, there are hard coded string index offsets for parsing the HTML.. it could be made dynamic, but would take longer than the 30 minutes it took to put this together... and it works fine for me as is. :)
Code:
# Just for fun, create a class to hold our item information. Not necessary, but I was playing around with custom types.. really easy to do in PS.
Add-Type @'
public class myItem
{
    public double regPrice;
	public double salePrice;
	public string name;
	public int sku;
	public int discount;
	public myItem(string n,int s,double rp,double sp)
	{
		regPrice = rp;
		salePrice = sp;
		name = n;
		sku = s;
		discount = (int)(100-(salePrice/regPrice*100));
	}
	public void print()
	{
		System.Console.WriteLine("Item Name:\t" + name);
		System.Console.WriteLine("Sku Number:\t" + sku);
		System.Console.WriteLine("Reg. Price:\t" + regPrice);
		if(salePrice == 8675309)
		{
			System.Console.WriteLine("Sale Price:\tAdd to Cart");
			System.Console.WriteLine("Discount:\tN/A");
		}
		else
		{
			System.Console.WriteLine("Sale Price:\t" + salePrice);
			System.Console.WriteLine("Discount:\t%" + discount + " Off");
		}
	}
}
'@    
# Empty array to hold the stores that we find with an item in stock
clear
$items= @()

# Your store number
$STORENUM=1438
$site = Invoke-WebRequest "http://www.bestbuy.com/site/olstemplatemapper.jsp?id=pcat17096&type=page&strId=$STORENUM&nrp=500&cp=1&sp=clearancePrice"

$content = $site.AllElements | Where Class -eq 'hproduct'

# Loop through each row in our table, each one contains store data (name, addr, zip, distance, stock, etc)
Foreach ($row in $content)
 {
		$html = $row.innerHTML.toLower()
		$html >> scrape2.html
		$nameStart = $html.indexOf('rel=product>')+12
		$nameStop = $html.indexOf('</a> </h3>') - $nameStart
		$salePriceStart = $html.indexOf('3836809_sale')+ 14
		
		
		$regPriceStart = $html.indexOf('reg. price: ') + 12
		
		
		$NAME = $html.Substring($nameStart,$nameStop)
		$SALEPRICE = $html.SubString($salePriceStart,10).Trim("<span")
		$REGPRICE= $html.SubString($regPriceStart,10).Trim("<span")
		$SKU = $html.SubString($html.indexOf('class=sku>')+10,10).Trim("</strong")
		if(!($REGPRICE -match '\$.*'))
		{
			$REGPRICE= $html.SubString($regPriceStart+20,10).Trim("</span")
		}
		if(!($SALEPRICE -match '\$.*'))
		{
			$SALEPRICE = "8675309" # A not-so-graceful way to handle when there isn't actually a price listed. :)
		}
		$SALEPRICE = $SALEPRICE.Trim("$")
		$REGPRICE= $REGPRICE.Trim("$")
		$DISCOUNT = [int](100-(($SALEPRICE/$REGPRICE)*100))
		
		$items += New-Object myItem($NAME,$SKU,$REGPRICE,$SALEPRICE);
		
		# Debug printing, not needed.
		# echo "Item Name:`t$NAME" 
		# echo "Item SKU:`t$SKU"
		# echo "Reg. Price:`t$REGPRICE" 
		# echo "Sale Price:`t$SALEPRICE" 
		# echo "Discount:`t%$DISCOUNT Off"
		# echo "--------------------------------------------------"
}
# Print out our items where discount is > 60%, sort, etc.
$items | Where-object discount -gt 60 | sort-object discount -descending

# Filter in other ways
# foreach ($item in $items)
# {
	# if (($item.discount -gt 75) -or ($item.regPrice -gt 200))
	# {
		# $item.print()
		# echo "----------------------------------------------------"
	# }
# }
 
Last edited:
Back