|
|
PowerShell Script Files - Add-contentPowerShell Script Files - Add-contentFew built-in cmdlets express their purpose as clearly as add-content. In fact the only danger with this command is 'over-think', just remember that PowerShell takes care of opening and closing files automatically. Consequently, there is no need to waste time looking for non-existent file-open, or file-save commands. If the file specified by Add-content does not exist, then PowerShell even creates it for you. Topics for Add-content
Example 1 Add-content, short and sweetHere is a PowerShell example that adds the string "Remember Mam's birthday" to a file called Memo.txt. I strongly recommend that you change the path from c: \Memo.txt to a folder such as c: \PowerShell\Memo.txt. If you need any help in executing the code, then see here. cls Learning PointsNote 1: Observe the classic verb-noun pairing add (verb) content (noun). Furthermore, the whole family use the singular word 'content'. Call for HelpWhen you experiment with a new PowerShell command, it benefits from being probed with Get-Help. As you study help and its examples, note how the position is important, For example: -path must be the first element, and -value in position two. 1) get-help add-content Example 2 Add-content, complete with two -parameterscls Learning PointsNote 1: I would like you to compare and contrast Example 2 with Example 1. My purpose is to show you that in you add values in the default positions, then you do not need to explicitly add the parameters. In this instance PowerShell can deduce what to do with the data for -path and -value, from the position of the text strings.
˚
The Content Family of CmdletsYou may have noticed from, 'help ac -full', that PowerShell supports a family of verbs that act upon the noun 'Content'. Add-Content There is also Out-File, a very useful command to save results to disk, rather than write to screen. See Also PowerShell Tutorials:• PowerShell Home • Com • Shell Application • Active Directory • QAD Snap-in • Get-Member Please write in if you see errors of any kind. Please report any factual mistakes, grammatical errors or broken links, I will be happy to not only to correct the fault, but also to give you credit.
*
|
|||||