PowerShell –SQL Automate Tutorial-4

Disclaimer:Hey Guys, this post contains affiliate link to help our reader to buy best product\service for them. It helps us because we receive compensation for our time and expenses.

InterServer Web Hosting and VPS

Scenario: PS is most powerful and very helpful tool for windows and SQL server administrator and automation. So its today need to learn at least basic of some PS cmdlets.

In this series of tutorial, we will only walk through some of the basis and need to know cmdlets which will helps us in future in order to manage our SQL server.

For more details, you can google and look for good site.

Note:- Please click here to get 3rd part of PowerShell –SQL Automate tutorial.


To get more information about PowerShell cmdlets, you can refer this link.

In this tutorial, we will walk through PowerShell Out-File cmdlets.


PowerShell Out-File

The Out-File cmdlet in PowerShell sends the output to a specific file. When you need to use its parameters, use this cmdlet instead of redirection operator (>).

Syntax
  1. Out-File   
  2. [-FilePath] <string>   
  3. [[-Encoding] {unknown | string | unicode | bigendianunicode | utf8 | utf7 | utf32 | ascii | default | oem}]   
  4. [-Append]   
  5. [-Force]   
  6. [-NoClobber]   
  7. [-Width <int>]   
  8. [-NoNewline]   
  9. [-InputObject <psobject>]   
  10. [-WhatIf]   
  11. [-Confirm]    
  12. [<CommonParameters>]  
  1. Out-File   
  2. [[-Encoding] {unknown | string | unicode | bigendianunicode | utf8 | utf7 | utf32 | ascii | default |oem}]   
  3. -LiteralPath <string>   
  4. [-Append]   
  5. [-Force]   
  6. [-NoClobber]   
  7. [-Width <int>]   
  8. [-NoNewline]   
  9. [-InputObject <psobject>]  
  10. [-WhatIf]   
  11. [-Confirm]    
  12. [<CommonParameters>]  

Parameters

Followings are the parameters used in this cmdlet:

-FilePath and -LiteralPath

Both the parameters are used to specify the path to the file in the command.

-Encoding

This parameter specifies the type of character used in the file. The default value of this parameter is UTF8NoBOM. Followings are the acceptable values for this parameter:

  • ASCII
  • Unicode
  • UTF7
  • BigEndianUnicode
  • UTF8
  • UTF8BOM
  • UTF8NoBOM
  • OEM
  • UTF32

-Append

This parameter is used to add the output at the end of an existing file.

-Force

This parameter overwrites the existing read-only files and the read-only attributes. It does not override security restrictions.

-NoClobber

This parameter prevents the existing files with the same name to be overwritten and shows you a message that the file already exists.

-Width

This parameter specifies the number of characters in each output line.

-NoNewLine

This parameter specifies that the content which is written to the file does not end with a new line character.

-InputObject

This parameter specifies those objects which are written to the file.

-WhatIf

This parameter describes what would happen if the cmdlet executes.

-Confirm

This parameter prompts you a confirmation before executing a cmdlet.

Example:

Happy Learning!


The world’s biggest power is the youth and beauty of a woman.

Chanakya