How it works...

Type Accelerators are another form of encapsulation of .NET code in PowerShell. Remember the first recipe in this chapter wherein we created a .NET object within PowerShell. We used the PowerShell command, New-Object -TypeName System.IO.DirectoryInfo -ArgumentList '/home/ram' to get information on a home directory: we created a new instance of System.IO.DirectoryInfo, and passed an argument to it. That was a lot of code to write. To accelerate the process, we could use, [IO.DirectoryInfo]'/home/ram', (System is the default namespace; PowerShell would understand it without us explicitly mentioning it when calling accelerators) which outputs the same object as the former command.

With Import-Csv on the other hand, the process was a simple conversion of data from text into name-value pairs. This is similar to using ConvertFrom-Text with a Delimiter parameter. This way, we instruct PowerShell to convert each row of text into instances of the object: The first row in the row-column structure is taken as the property name, and the rest of the rows are data. The cells are separated using  delimiter, which was a comma, in case of the CSV file.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.234.62