|
|
Sponsor
Symantec
Learn the Best
Practices for Backup and Recovery
Data and system loss from a hard drive failure, attack, natural
disaster, or error can happen anytime. Make sure you have a secure recovery strategy
in place with Symantec’s latest backup and system
recovery
technology. Register today for our upcoming Best Practices for Backup and Recovery webcast
and learn how to restore Windows data from
Microsoft® Exchange, Active Directory, SQL, and SharePoint in seconds,
restore systems to dissimilar hardware or virtual systems in minutes,
and back up data
and system information to offsite locations to properly secure, back up, and
archive critical data. Register now for the Tuesday, May 6 webcast at 9
am PDT/12 pm EDT.
www4.symantec.com/offer?a_id=59691
|
|
Articles
Q. How can I use Windows PowerShell to
read and use a comma-separated value (CSV) file?
by John
Savill
4.14.08
A. The PowerShell cmdlet Import-csv lets you read
and manipulate a CSV file. The following code and output is an example
of the command you would use to view a CSV file. Take note that the
CSV's first row defines each column.
D:\Documents\Books\Complete Windows Longhorn\Images> import-csv "Chapter
3 Image Names.csv"
The return would be:
Old Name new name
-------- --------
3-inst1.tif 03wls01.tif
3-inst2.tif 03wls02.tif
3-inst3.tif 03wls03.tif
3-inst4.tif 03wls04.tif
The cmdlet’s real strength is manipulating the output. For example,
while writing The Complete Guide to Windows Server 2008, I used
my own image-naming format, which wasn't the correct format for the
final production manuscript. So I used a CSV file to rename the
documents, mapping the old name to its true standards-based name.
To access each CSV-file row of data, you must acquire each as an object.
Then, examine the values named by each column by using code similar to
the following:
PS D:\Documents\Books\Complete Windows Longhorn\Images> import-csv
"Chapter 3 Image Names.csv" | foreach-object {write-host $_."old name"
$_."new name"}
The return would be:
3-inst1.tif 03wls01.tif
3-inst2.tif 03wls02.tif
3-inst3.tif 03wls03.tif
3-inst4.tif 03wls04.tif
You'll notice that I placed column names only in quotes because I have a
space in the column names. I can rename a column by changing write-host
to rename-item, similar to the following sample code, and I'm done:
PS D:\Documents\Books\Complete Windows Longhorn\Images> import-csv
"Chapter 4 Image Names.csv" | foreach-object {rename-item $_."old name"
$_."new name"}
Q. How I can I use Windows PowerShell
to get a count of all of my machine's services?
by John
Savill
4.15.08
A. The Get-Service cmdlet returns information
about all services. You can easily pass this output to a loop that
increments a counter. The following code provides an example:
Users\john.SAVILLTECH> Get-service | foreach {$t=0} {$t +=1} {"Total
services: $t"}
The return is:
Total services: 144
How does this work? The Foreach cmdlet has three sections. The first
runs the {$t=0} variable once to set it to zero. The second section, {$t
+=1}, increments the variable by one for each service, and the final
section, {"Total services: $t"}, displays the variable's value when the
cmdlet finishes.
Q. How can I use Windows PowerShell to
return a list of machine services in a designated
state?
by John
Savill
4.16.08
A. You can use PowerShell to examine a service
object's Status property. You query the Status property with the
Where-Object cmdlet, for example, to list only running services, as
follows:
get-service | where-object {$_.status -eq "Running"}
Q. How can I use Windows PowerShell to
return a list with only unique values?
by John
Savill
4.17.08
A. Getting a list with only unique values is easy
with PowerShell. Pass your list of unique values to the Get-Unique
cmdlet—as the following code shows—and PowerShell will output only
the unique instance:
Users\john.SAVILLTECH> 1,1,1,1,2,2,2,3,4,4,4,4,5,6,6,6,7,7,7,7,4,5 |
get-unique
The return is:
1
2
3
4
5
6
7
4
5
This return includes a duplicate 4 and duplicate 5 at the end. The
cmdlet returned only unique values for adjacent values, which is how the
cmdlet works. To avoid this problem, first use the Sort-Object cmdlet to
sort the list, as in the following example:
Users\john.SAVILLTECH> 1,1,1,1,2,2,2,3,4,4,4,4,5,6,6,6,7,7,7,7,4,5 |
sort-object | get-unique
Using the Sort-Object cmdlet, you'll get the following return:
1
2
3
4
5
6
7
Q. How can I use Windows PowerShell to
quickly check whether a particular year is a leap
year?
by John
Savill
4.18.08
A. The DateTime library has an isleapyear
function to quickly check whether a designated year is a leap year. If
the year is a leap year, a true value will return, and if not, a false
value will return. The following example uses the DateTime library to
check whether 2008 is a leap year:
Users\john.SAVILLTECH> [system.datetime]::isleapyear(2008)
The return is:
True
The following command checks whether 2009 is a leap year:
Users\john.SAVILLTECH> [system.datetime]::isleapyear(2009)
The return is:
False
To see all the members of system.datetime, pass the class to the
Get-Member cmdlet, as follows:
[system.datetime] | get-member
You can use this technique to check members with any PowerShell class or
object. It's a great way to determine an object's properties and
actions.
Events & Resources
Security Horror Story
Contest!
Tell us about a security hole that you found, a virus
that shut down your network, an embarrassing or scary near-miss, or
direct hit. (Be sure to describe how you solved the problem too.) We'll
print the best tales in a Windows IT Pro cover story
(anonymously, if you like), and you'll win a one-year Windows IT
Pro VIP subscription.
This includes access to every article ever printed in Windows IT
Pro, SQL Server Magazine, Exchange and Outlook Pro VIP,
Scripting Pro VIP, and Security Pro VIP.
Send your security horror stories (no more than 500 words) to Lavon
Peters (lpeters@windowsitpro.com) by May 9.
Backup, Recovery, and Testing for
Exchange in a Single, Easy-to-Configure Integrated App
Read how a comprehensive protection solution lets you
dispense with your backup applications, bare-metal recovery solutions,
test recovery hardware, and a lot of worry. See how you can extract any
Microsoft Exchange item or folder without interrupting the performance
of the live Exchange server. Download this white paper today!
http://windowsitpro.com/whitepapers/Index.cfm?fuseaction=ShowWP&wpid=43065da9-c439-4d63-b079-df04eb60d393&code=042308er
SharePoint in Action: Developing and
Deploying Real-World Solutions
Free Online Conference -- May 13, 2008
Get the facts about Microsoft Office SharePoint Server and Windows
SharePoint Services in this free, online event on May 13, 2008. This
event addresses common business uses of SharePoint and is relevant for
companies of any size and any vertical market. You'll come away with an
understanding of how to deploy and implement SharePoint effectively in
your organization.
http://events1.unisfair.com/index.jsp?eid=268&seid=25&code=editnewsletters
Keep Your Exchange Server
Healthy
Fear of loss compels us to protect ourselves. Although
no one's life is in danger from a messaging system, the welfare of your
data could be. Read this white paper to learn the bare and necessary
facts you should know to proactively maintain your Exchange Server 2007
environment.
http://windowsitpro.com/Whitepapers/Index.cfm?fuseaction=ShowWP&WPID=393a7bec-e173-483c-b887-95b1cf858e28&code=042308er
Featured White Paper
Top 7 Benefits of Server-Hosted
Desktops
This white paper explains the distinct advantages of
server-based computing. Learn the benefits of server-hosted desktops and
how to obtain those benefits. To begin saving money and gain
flexibility, download this white paper today!
http://windowsitpro.com/whitepapers/Index.cfm?fuseaction=ShowWP&wpid=ad7cc518-087b-4d5c-aa53-2337758a7909&code=042308er
Announcements
EXCHANGE 2007 Mastery Series--May 29,
2008
3 information-packed eLearning seminars for only
$99!
Hosted by Windows IT Pro
Join Mark Arnold, MCSE+M and Microsoft MVP, as he coaches you through
server management in Exchange 2007:
- Learn the Pros and Cons of Your Mailbox High-Availability Options
- See Real-World Examples of Transport Rules You Can Implement in Your
Environment
- Windows PowerShell: Get Started with Basic Commands
For more information and to register, go to http://windowsitpro.com/elearning/index.cfm?fuseaction=dynamic&v=5119&p=5161&code=&eventid=29&code=update
Vote in the 2008 Windows IT Pro
Community Choice Awards!
Final voting for the Windows IT Pro Community
Choice Awards is now open! Voting in this awards program is open to all
Windows IT Pro Web site visitors, but vendors whose products are
nominated are prohibited from voting. Click on the link below to enter
the voting tool:
Windows
IT Pro - Community Choice Awards
Voting will close on May 23rd, 2008 at 11:45pm MST.
Windows IT Pro Master CD: Take
the Experts With You!
Find the solutions you need within the thousands of
searchable articles, helpful bonus content, and loads of expert advice
on the Windows IT Pro Master CD. A Master CD subscription buys
you portable access to the entire Windows IT Pro article database
plus exclusive access to the new articles we publish on WindowsITPro.com
every day. It's like having a team of consultants in your pocket! Get
real-world solutions fast--order the Windows IT Pro Master CD
today.
https://store.pentontech.com/index.cfm?s=1&promocode=EU2284WC&
|
|
If you use a product that has made a tremendous impact in your
organization and is a product that you can't live without, tell us about
it at whatshot@windowsitpro.com
and we'll feature your review in a future issue of the magazine, under
the "What's Hot" section.
|
|