778
Part V: Enterprise Data Management
When this script is run on a server, it returns results such as this:
Name : POSHSQL
Model : 43192PU
Manufacturer : LENOVO
Description : AT/AT COMPATIBLE
DNSHostName : POSHSQL
Domain : WORKGROUP
DomainRole : 0
PartOfDomain : False
NumberOfProcessors : 1
SystemType : x64-based PC
TotalPhysicalMemory : 17108058112
UserName : POSHSQL\Aaron.Nelson
Workgroup : WORKGROUP
Name : Microsoft Windows 7 Ultimate
|C:\Windows|\Device\Harddisk0\Partition2
Version : 6.1.7601
FreePhysicalMemory : 11955708
OSLanguage : 1033
OSProductSuite : 256
OSType : 18
ServicePackMajorVersion : 1
ServicePackMinorVersion : 0
Name Capacity DeviceLocator Tag
---- -------- ------------- ---
Physical Memory 4294967296 DIMM 1 Physical Memory 0
Physical Memory 4294967296 DIMM 2 Physical Memory 1
Physical Memory 4294967296 DIMM 3 Physical Memory 2
Physical Memory 4294967296 DIMM 4 Physical Memory
Name FreeSpace Size
---- --------- ----
C: 11414634496 119926681600
E: 49521369088 240054693888
Anytime a set of commands is used repeatedly, it’s useful to encapsulate those commands
in a function. Functions must be defi ned before they can be used because PowerShell is an
interpretive language and doesn’t “read ahead” to see what functions might be defi ned later.
Best Practice
Avoid scripting. This means you should write your chunks of code into modular, repeatable code and
place that inside of functions. After you create a number of custom functions, place those functions
into a PowerShell Module; then import the whole Module when you need it. For more information
on not scripting, see http://blogs.technet.com/b/heyscriptingguy/archive/2011/06/26/
dont-write-scripts-write-powershell-functions.aspx
c30.indd 778c30.indd 778 7/31/2012 9:46:22 AM7/31/2012 9:46:22 AM
http://www.it-ebooks.info