How to use the PowerShell ConvertFrom- CSV Cmdlet to Save Coding Time with PS Script

Home > Videos > PowerShell > How to use the PowerShell ConvertFrom- CSV Cmdlet to Save Coding Time with PS Script

How to use the PowerShell ConvertFrom- CSV Cmdlet to Save Coding Time with PS Script

Like This Video 0 278 Jason Yoder
Added by March 2, 2018

In this video, PowerShell instructor Jason Yoder shows how to use the ConvertFrom-CSV PowerShell Cmdlet to easily convert standard CSV files into PowerShell objects and speed up coding time.

For instructor-led PowerShell training classes, see our course schedule:

Microsoft Windows PowerShell Training

PowerShell ConvertFrom-CSV script used in this video.

Download ConvertFrom-CSV PowerShell Script


Video Trascription

I’m Jason Yoder with Interface Technical Training. Today I’m going to show you a PowerShell cmdlet that might help you reduce the amount of coding that you need to do.

When we’re asking for information from our environments it’s usually from some controlled source. Maybe it’s Active Directory. Maybe we’re getting it from SharePoint. Maybe we’re getting it from Azure. We have control of this and we know what type of information we’re going to receive.

Other times you’re going to be asking for information from the Internet and it may not come in a format that works well with PowerShell. We have this saying, “Object in, Object out.” What that means is that we expect an object to be received by our PowerShell cmdlets.

Remember an object is a packet of data that contains readable information to the computer. We also expect object out, which means anything that we produce we want to make sure it makes an object so that the next cmdlet in the pipeline can accept it.

Let’s take a look at a little situation here. We’re going to go ahead and download some information from the Internet. As you can see, here’s where we’re receiving some stock information. I understand what the first two fields mean, but after that I have no idea really what the rest of this is trying to tell me, because there’s no headers to this.

I’m not really sure what kind of information I’m looking in. It looks comma separated to me. What I am going to do is I am going to ask for this information again and I’m going to store it in a variable called Data. When I display Data, there’s that information.

I am kind of questioning here, what can I do with this? What data type am I working with? I’m going to run the get type method against that variable and it tells me that I’m working with string. If you’ve worked with a string object before, you know there’s only one property in string and that’s called length. It’s the number of characters that it contains.

I’m interested in what those actual numbers are. I need to convert them some way to make it readable to PowerShell. In the past people would write a lot of different types of code in order to segment out that line.

For example, we’re going to go ahead and run the split method. I can clearly see the different elements of that string, but I still do not have any header information. I cannot let PowerShell read this.

What we’re going to do it we’re going to work with a convert from CSV cmdlet. I’m going to go ahead and open up its help file, and just draw your attention to the top. “Converts object properties in comma separated value format into CSV versions of the original object.” In layman’s terms it’s going to take this string and if we do things right it’s going to make it an object out of the CSV file.

Let’s see what happens. I’m just going to go ahead and pipe my information straight to it, and nothing. Something is not quite right here. Let’s take a look at one of the parameters in the help file for a convert to CSV. It’s called Header.

This is where this cmdlet’s going to shine for us because instead of us writing a bunch of code to populate different properties for this object, it’s going to do the work for us. Header specifies an alternate column header row for the imported string. The column header determines the names of the properties of the objects that convert from CSV creates.

You can see I’m using it here and I’m providing a name for each one of the values that’s inside of this CSV string. If we look, I’m going to have Symbol be the first property header. I’m going to have Name be the second, and so on and so forth. You do have to provide them in order. It has no idea what you’re talking about. You must have them in order.

Let’s go ahead and run this. Now you can see that we have a PowerShell object created. Over here on the right we have properties and over here on the left we have their values. Now we can feed this into the PowerShell pipeline and use this. This data’s in a format that a computer can understand.

Just to show you, I’m going to go ahead and run this again and pipe it to get Member. You can see that we have an object. We can now use it with PowerShell.




Videos You May Like

A Simple Introduction to Cisco CML2

0 1942 0

Mark Jacob, Cisco Instructor, presents an introduction to Cisco Modeling Labs 2.0 or CML2.0, an upgrade to Cisco’s VIRL Personal Edition. Mark demonstrates Terminal Emulator access to console, as well as console access from within the CML2.0 product. Hello, I’m Mark Jacob, a Cisco Instructor and Network Instructor at Interface Technical Training. I’ve been using … Continue reading A Simple Introduction to Cisco CML2

Using Navigation Controls in a Collaboration Site in SharePoint

0 343 1

In this SharePoint training video, I want to talk about the Navigation Controls in SharePoint. They tend to fall into two kind of different categories; one with the navigation controls in a typical Collaboration Site such as a Team Site or a Project Site. These are Sites that are based on the Team Site Template … Continue reading Using Navigation Controls in a Collaboration Site in SharePoint

Windows 10 Features and Navigation – December 1, 2015

0 123 1

In this recorded Windows 10 webinar from December 1,2015, Windows Instructor Steve Fullmer presents the navigation and some of the new features associated with Windows 10 including Sysinternals Tools for Windows Client, Windows core concepts, exploring Process Explorer as well as some of the features that are not yet ready for prime time but will … Continue reading Windows 10 Features and Navigation – December 1, 2015

Write a Comment

Share your thoughts...

Please fill out the comment form below to post a reply.