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 4th 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 Get-location cmdlets.



Get-Location

The PowerShell Get-Content cmdlet gets the content of an item at a specified location.

Syntax

Get-Content   
[-Filter <string>]   
[-Include <string[]>]   
[-Exclude <string[]>]   
[-Force]  
[-Path] <string[]>   
[-ReadCount <long>]   
[-TotalCount <long>]   
[-Tail <int>]   
[-Credential <pscredential>]  
[-UseTransaction]   
[-Delimiter <string>]   
[-Wait]   
[-Raw]   
[-Encoding {Unknown | String | Unicode | Byte | BigEndianUnicode | UTF8 | UTF7 | UTF32 | Ascii | Default | Oem | BigEndianUTF32}]  
[-Stream <string>]    
[<CommonParameters>]  

-Filter

The -Filter parameter is used to specify a filter to qualify the -Path parameter. The FileSystem provider is the only PowerShell provider that supports the uses of filters. This parameter is more efficient as the provider applies the filters when the cmdlet gets the object, rather than having Powershell filters the object after they are accessed.

Include

The items that this cmdlet includes in the operation are specified as a string array. The value of -Include parameter qualifies the -Path parameter. Enter a pattern or a path element, such as *.txt. The characters of wildcard are permitted. It is effective only when the cmdlet includes the contents of an item, such as C:\*, the wildcard character ‘*‘ is used to specify the contents of the C: directory.

-Exclude

The items that this cmdlet excludes in operation are specified as a string array. The value of -Exclude parameter qualifies the -Path parameter. Enter a pattern or a path element, such as *.txt. The characters of wildcard are accepted. The -Exclude parameter is effective only when the cmdlet includes the contents of an item, such as C:\*, the wildcard character ‘*‘ is used to specify the contents of the C: directory.

-Force

The -Force parameter will override the read-only attribute or creates the directories to complete a file path. It does not attempt to change the file permissions or override the security permissions.

-Path

The -Path parameter is used to specify the path to an item where this cmdlet gets the content. Wildcard characters are accepted. The paths must be the paths to the items, not to containers.

-ReadCount

The -ReadCount parameter is used to specify how many lines of the content are sent through the pipeline at a time. It does not change the content to be displayed, but it affects the time taken to display the content.

-TotalCount

The -TotalCount parameter is used to specify the number of lines from the beginning of the file. We can also use the aliases First or Head of this parameter.

-Tail

The -Tail parameter is used to specify the number of lines from the end of the file. It was introduced in Windows PowerShell 3.0. We can also use the alias Last of this parameter.

-Delimiter

The -Delimiter parameter is used in this cmdlet to divide the file into objects while it reads. We can use this parameter to split the large files into smaller files by specifying a file separator, as a delimiter.

It is preserved and becomes the last item in the section of each file. It is a dynamic parameter which is added by the FileSystem provider to the Get-Content cmdlet.

-Wait

The -Wait parameter is used to keep the files open after all the existing lines have been output.

It is a dynamic parameter which is added by the FileSystem provider to the Get-Content cmdlet. This parameter cannot be combined with the -Raw parameter.

-Raw

The -Raw parameter is used to ignore the newline characters and returns the whole content of a file in a single string. In the file, the newline characters are used as delimiters by default to separate the inputs into an array of string. It was introduced in Windows PowerShell 3.0.

It is a dynamic parameter which is added by the FileSystem provider to the Get-Content cmdlet

-Encoding

The -Encoding parameter is used to specify the type of encoding for the target file. Its default value is UTF8NoBOM.

Following are the acceptable values for this parameter:

  • ASCII: This value uses the encoding for the ASCII (7-bit) character set.
  • Unicode: It encodes in UTF-16 format using the little-endian byte order.
  • UTF7: It encodes in UTF-7 format.
  • UTF8: It encodes in UTF-8 format.
  • BigEndianUnicode: It encodes in UTF-16 format using the big-endian byte order.
  • OEM: It uses the default encoding for MS-DOS and console programs.
  • UTF8NoBOM: It encodes in UTF-8 format without Byte Order Mark (BOM)
  • UTF32: It encodes in UTF-32 format.
  • UTF8BOM: It encodes in UTF-8 format with Byte Order Mark (BOM)

It is a dynamic parameter which is added by the FileSystem provider to the Get-content cmdlet. It is available only in the drives of a file system.

-Stream

The -Stream parameter is used to get the content of the specified alternative NTFS file stream from the file. Wildcard characters are not supported. It was introduced in Windows PowerShell 3.0.

It is a dynamic parameter which is added by the FileSystem provider to the Get-content cmdlet and works only in the file system drives.


Examples

Example1: To get the content of a text file

Happy Learning!


Test a servant while in the discharge of his duty, a relative difficulty, a friend in adversity, and a wife is misfortune

Chanakya

One thought on “PowerShell –SQL Automate Tutorial-5

Comments are closed.