Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Instant Windows PowerShell Guide

You're reading from   Instant Windows PowerShell Guide Enhance your knowledge of Windows PowerShell and get to grips with its latest features

Arrow left icon
Product type Paperback
Published in Nov 2013
Publisher Packt
ISBN-13 9781849686785
Length 86 pages
Edition 1st Edition
Arrow right icon
Author (1):
Arrow left icon
Harshul Patel Harshul Patel
Author Profile Icon Harshul Patel
Harshul Patel
Arrow right icon
View More author details
Toc

Operate the data (Intermediate)


Data Operations are critical routine administrative tasks and, with the release of Windows PowerShell Version 3.0, we have made some improvements regarding the handling of data in the console.

Getting ready

There are a few new operators introduced in PowerShell Version 3.0. For example, the In and NotIn operators.

How to do it...

Try executing the following code:

  1. The following command checks the availability of 1 in the reference set and returns True in this case:

    PS C :\> 1 -In (1,2,3)
    True
    
  2. The following command checks for an exact counter match for the Admin keyword in the reference set and returns True in this case:

    PS C :\> "Admin" -NotIn "Administrator"
    True
    

How it works...

The following table mentions the syntaxes for these operators:

Operator

Syntax

Description

-In

<Test-value> -In <Reference-values>

This operator returns a Boolean value as output. If any test value is present in the reference values set, it returns True, else False.

-NotIn

<Test-value> -NotIn <Reference-values>

This operator also returns a Boolean value as output. If any test value is not present in the reference values set, it returns True, else False.

There's more…

There are a few new parameters introduced with the following CMDLETs:

Get-Content

The Get-Content CMDLET retrieves content from a specified file.

  • -Tail <Int32>: To retrieve the number of lines from the file, use the Tail parameter with the Get-Content CMDLET. It retrieves the number of lines supplied to this parameter. For example:

    PS C :\> Get-Content -Path C:\PSTest.txt -Tail 10
    

    The preceding command statement retrieves the last 10 lines from C:\PSTest.txt.

Tip

You can use the –Last instead of the Tail parameter; it is an alias of this parameter.

Tee-Object

The Tee-Object CMDLET stores output in a file or variable and throws to the pipeline.

  • -Append [<SwitchParameter>]: If any file already exists and you try to supply it with Tee-Object, it overrides the content by default. To avoid this, you can use the –Append parameter with the Tee-Object CMDLET. For example:

    PS C:\>Get-ChildItem -Path C:\PSBooks -Recurse | Tee-Object -File C:\BookList.txt –Append
    

    The preceding command statement gets the list of PowerShell books and appends it to BookList.txt.

You have been reading a chapter from
Instant Windows PowerShell Guide
Published in: Nov 2013
Publisher: Packt
ISBN-13: 9781849686785
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image