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.
There are a few new operators introduced in PowerShell Version 3.0. For example, the In
and NotIn
operators.
Try executing the following code:
The following command checks the availability of
1
in the reference set and returnsTrue
in this case:PS C :\> 1 -In (1,2,3) True
The following command checks for an exact counter match for the
Admin
keyword in the reference set and returnsTrue
in this case:PS C :\> "Admin" -NotIn "Administrator" True
The following table mentions the syntaxes for these operators:
Operator |
Syntax |
Description |
---|---|---|
|
|
This operator returns a Boolean value as output. If any test value is present in the reference values set, it returns |
|
|
This operator also returns a Boolean value as output. If any test value is not present in the reference values set, it returns |
There are a few new parameters introduced with the following CMDLETs:
The Get-Content
CMDLET retrieves content from a specified file.
-Tail <Int32>
: To retrieve the number of lines from the file, use theTail
parameter with theGet-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
.
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 withTee-Object
, it overrides the content by default. To avoid this, you can use the–Append
parameter with theTee-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
.