Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  Advanced Search 


April 29, 2008

A Common Misconception About PowerShell's kb, mb, and gb Operators


RSS
View this exclusive article with VIP access -- click here to join |
See More Scripting Articles Here | Reprints | Or sign up for our VIP Monthly Pass!
Main Article    Windows PowerShell Range Operator Tricks

People occasionally refer to PowerShell's kb, mb, and gb operators as constants. However, they aren't constants; they're operators. As of this writing, even some Microsoft documentation makes this mistake (http://www.microsoft.com/technet/scriptcenter/resources/pstips/jun07/pstip0608.mspx).

PowerShell does have values called constants. (Although they aren't precisely what most scripting and programming languages would call constants.) However, they behave nothing at all like the kb, mb, and gb operators. The difference can best be seen through an example.

In PowerShell, you can use the New-Variable cmdlet to create a constant. For example, the statement

New-Variable -Name kb -Value 1024 -Option Constant

creates a constant named kb, which has the value of 1024. You can then use this constant to find out how many bytes there are in 32 binary kilobytes (32KiB) by multiplying it by 32:

32 * $kb

As this example shows, when using a constant, you have to precede its name with a dollar sign ($) so that PowerShell recognizes it as a named value. The arithmetic * operator is used to perform the multiplication. . . .

Reader Comments

You must log on before posting a comment.

If you don't have a username & password, please register now.




Top Viewed ArticlesView all articles
Friday at PASS Europe 2006

Kevin talks about the closing day of the event and shares a funny Microsoft film. ...

PsExec

This freeware utility lets you execute processes on a remote system and redirect output to the local system. ...

Escape From Yesterworld

Kevin points you to the funniest SQL Server website ever! ...


Related Events PowerShell 101 - eLearning Series

Check out our list of Free Email Newsletters!

Scripting eBooks Keeping Your Business Safe from Attack: Encryption and Certificate Services

Best Practices for Managing Linux and UNIX Servers

Building an Effective Reporting System

Related Scripting Resources Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro Windows Dev Pro IT Job Hound ITTV
IT Library Technology Resource Directory Connected Home Windows Excavator Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing