Learn PowerShell: Episode 3, Variables + NoteProperties + CSV Files

Ғылым және технология

In this video we take our knowledge of PowerShell even further, using "NoteProperty" to make custom properties, using "variables" to hold onto objects and read/writing to CSV files, and much more! All coming up, in this new episode of the beginners' PowerShell tutorial series.
The CSV file I used ►abco.live/download/2021/stude...
The video starts with variables, a critical tool we can use to help us get things done easier. It allows us to hold onto objects so we can continually re-use them again and again, letting us write shorter, more concise commands. In addition, this mechanism of holding onto objects allows us to take full advantage of our system. Reducing CPU usage and memory usage, just from such a simple construct.
We'll then look at an extremely powerful and simple command called "Import-Csv", which allows you to take any CSV file and immediately read it into objects that you can then operate on and work with.
After that, we'll use what we learnt from using "Import-Csv" in order to help us investigate converting from one kind of data to another. We'll learn about what the difference between text and numbers are to the computer, as well as how to go from one to the another within PowerShell, as well as what CSV's fundamental flaw is when it comes to different types of data.
Next, we'll take a look a "NoteProperty". This is an extremely useful type of member you can get on an object that allows you to attach your own custom property to any object you want. Allowing you to work in an even more detailed and systematic way.
We'll then use these "NoteProperty"s alongside a command called "Export-Csv" to help us modify the CSV and add a new column. Filling this column with values, adding numbers, and viewing these note properties will all be made clear in the video.
PS: This episode was also the first one on the entire channel to be edited 100% within the video editor. Previously, the videos were edited using a combination of two programs:
- The video editor for editing the audio, cutting up the screen recording footage, adjusting the audio levels etc.
- The graphics program used to create all the animated sequences and graphics.
The graphics produced by the graphics program were then edited into the video through the editor, and timed up with the audio and screen recording, allowing it to all be seen as one single video.
However, this video is a new step in the evolution of ABMedia in that it doesn't use the graphics program at all! Everything seen in this video was created directly from the video editor. This new style of producing the videos should allow for a quicker production time (after some setting up time is allowed to fully set up all the presets properly for it), and it should hopefully in the future allow the graphics seen throughout the video to get even more involved in the actual screen recording footage, allowing all kinds of new views and an even more coherent flow than was ever possible before with the static images present in the graphics previously.
This shouldn't affect the visual quality of the series at all. As a matter of fact, the graphics in the video look almost identical to the previous one, it's just a specific detail of exactly how it's now being done behind the scenes - and a new step in the right direction for ABMedia's development as a high-quality, well-edited brand of videos.
Thank you for your support of ABMedia. Just by watching and enjoying these videos, you are helping out immensely in supporting the channel and its development. Thank you very much for reading this description too, all videos have detailed descriptions, thumbnails, subtitles and content to try and allow the highest accessibility and surrounding content as possible.
Chapters:
0:00 Variables
6:38 CSV Files
9:48 Casting
12:52 NoteProperties
16:40 Custom Properties
19:43 Putting It Together
Thanks for watching my video, before are some general ABMedia links if you are interested:
Website ► abco.live/
Discord ► abco.live/discord
The Discord server is a place to chat with the creator of this video, as well as anyone who contributed to its development and has helped support ABWorld over the years.
A huge thank you goes to @ndumiphotos (on Instagram) for the graphics used in the intro.
#learnpowershell #powershell

Пікірлер: 82

  • @user-gf7nh2tk7c
    @user-gf7nh2tk7c7 ай бұрын

    Wow, thank you so much for the natural way of explaining things in Powershell! Very clear, concise and memorable!

  • @ABCo-ABMedia

    @ABCo-ABMedia

    7 ай бұрын

    Thank you!

  • @lewishamilton9941
    @lewishamilton99417 ай бұрын

    These tutorials are probably the best I have come across. The presenter has natural expression and emphasis which makes the lessons feel personal. His typing is excellent without errors and constant corrections.

  • @ABCo-ABMedia

    @ABCo-ABMedia

    7 ай бұрын

    Thanks, glad you like it! Interesting points for sure

  • @sinestesiagarcia8484
    @sinestesiagarcia84842 жыл бұрын

    The first course that makes actually enjoyable learning PS. You are a talented teacher, my friend!

  • @ABCo-ABMedia

    @ABCo-ABMedia

    2 жыл бұрын

    Glad to hear you like it!

  • @iamjojo999

    @iamjojo999

    9 ай бұрын

    I'm so glad I found this channel while two days ago I decided to learn powershell. Your style of teaching for me is an enjoy, and I believe so for others. Good job.

  • @Cypryn

    @Cypryn

    5 ай бұрын

    I agree. I hope this channel will pop and be rewarding enough for him to make more materials like this one.

  • @MunnyLerner
    @MunnyLerner5 ай бұрын

    11:10 "You are learning stuff that applies to full on programming languages in this series". Exactly why I'm here :) Thanks, this is awesome! Edit: Was not expecting that extremely cool NoteProperty technique at the end, that's epic!

  • @GraysonSedory
    @GraysonSedory2 жыл бұрын

    These videos deserve more likes and views, keep up the good work!

  • @BarrySwords
    @BarrySwords Жыл бұрын

    Great video course! So glad I discovered it. You have a great way of explaining things.

  • @ABCo-ABMedia

    @ABCo-ABMedia

    Жыл бұрын

    Happy to hear you think so!

  • @kingstonvong5470
    @kingstonvong54705 ай бұрын

    thank you so much! you made powershell easily to learn ^^

  • @ABCo-ABMedia
    @ABCo-ABMedia3 жыл бұрын

    Episode 4 is just a week away! Get excited... Maybe!

  • @taulguedi637
    @taulguedi637 Жыл бұрын

    Excellent. I like it a lot. You are a great teacher. See you in the next video!

  • @kalpitkatpara2720
    @kalpitkatpara2720 Жыл бұрын

    Amazing Series!!! love it! Thank you so much for making such a great content!

  • @ABCo-ABMedia

    @ABCo-ABMedia

    Жыл бұрын

    Glad you like it

  • @emmanuelpaniagua8983
    @emmanuelpaniagua8983 Жыл бұрын

    Great Series!!!!! thanks for such awesome Content

  • @juansanchez6685
    @juansanchez6685 Жыл бұрын

    Fantastic video one more time!

  • @jimlayland4161
    @jimlayland4161 Жыл бұрын

    Another fantastic video.....on to the next :)

  • @jasonmoore4429
    @jasonmoore44292 жыл бұрын

    An easier way to cd where you want to go is to grab the file or dir and drop it into Powershell and it will auto-fill the correct path

  • @ABCo-ABMedia

    @ABCo-ABMedia

    2 жыл бұрын

    Yep, thanks for the extra little tip. That is a thing the _host_ window that holds PowerShell provides, and is a neat trick.

  • @sarahoseghale2511
    @sarahoseghale2511 Жыл бұрын

    you are an extraordinary teacher.

  • @FernandoLopez-el8mp
    @FernandoLopez-el8mp2 жыл бұрын

    Really Great!

  • @ABCo-ABMedia

    @ABCo-ABMedia

    2 жыл бұрын

    Happy to hear it!

  • @zeelpatel9321
    @zeelpatel93212 жыл бұрын

    Best video series ever for PS on KZread, Legendry to be fair

  • @xdasdaasdasd4787
    @xdasdaasdasd4787 Жыл бұрын

    These are great, sad to see you stopped

  • @ABCo-ABMedia

    @ABCo-ABMedia

    Жыл бұрын

    I haven't stopped! There's still two episodes left to go on the series (then it'll be complete), just been caught up with other stuff: I've not abandoned the series or the channel, it will come back! :)

  • @codedunit5096
    @codedunit50963 жыл бұрын

    Noice job!

  • @kiltsandcomputers
    @kiltsandcomputers Жыл бұрын

    Thank you for such an outstanding and easy to understand explanation of why Import-Csv doesn't properly assign things like numbers as integers, which also carries over to dates (which need to be casted to [datetime])

  • @ABCo-ABMedia

    @ABCo-ABMedia

    Жыл бұрын

    Indeed, glad you felt it was effective! I always want to make sure everything is really clear in these videos!

  • @honsok7660
    @honsok76602 жыл бұрын

    생성된 object에 원하는 property를 하나 더 넣을 수 있는지 몰랐었네요 ^^ 좋은 정보 감사합니다. 노마드코더 니꼴라스님 목소리 같은데 맞나요?

  • @barry5462
    @barry54622 жыл бұрын

    Hello, Im really enjoying these videos,but i have two problems 1.When i type $students = Import-Csv -Path 'test.csv',i get the following error, Import-Csv could not find the file in 'C :\Users`\Barry\test.csv' I downloaded your file and saved it in documents,in notepad... 2....11:27 on your video When i write out the maths part,i get this error, Invalid Operation.The property 'Maths' cannot be found on this object.Verify that the object exists and can be set Sorry if this sounds really basic,but im new to powershell and scripting in general..Im using these videos to put on my CV,as im looking for an entry level job in I.T

  • @ABCo-ABMedia

    @ABCo-ABMedia

    2 жыл бұрын

    1. If you saved it in documents, you'll need to _go_ to the "Documents" folder in PowerShell, otherwise it's going to look in "C:\Users\Barry" and not "C:\Users\Barry\Documents". If you look at your PowerShell window, to the left of where you type commands it always tells you what folder you're in. If you want to change folders you can use the command "cd". So, in your case, your PowerShell is in the folder "C:\Users\Barry" - and you can type "cd Documents" to go into "C:\Users\Barry\Documents". Now accessing "test.csv" won't be an issue. Or, instead of using "cd", you could also write "Documents\test.csv" to tell it to look for it in the Documents folder. 2. Well if you got an error reading the CSV file, then it's not going to put all the proper properties onto the objects (in fact, it won't give anything back at all), so that will naturally happen later on if it fails to read the CSV file.

  • @fabhi
    @fabhi2 жыл бұрын

    Quick question, silly doubt. So Add-Member modifies the properties of the object and does not create a new object everytime and replace that with the old object? So, the command does inplace modification rather than outplace?

  • @ABCo-ABMedia

    @ABCo-ABMedia

    2 жыл бұрын

    Yes, it modifies the properties of the object - doesn't create a new one. If it made a new one with the properties added it would have to give that new object back

  • @adnanlaghzaoui2591
    @adnanlaghzaoui2591 Жыл бұрын

    Hey Alex ! Thank you very much for these wonderful videos, 1st time ever i finally get what's going on so far and nice speechflow. However, im stuck with this bloody csv file because i can't figure out how you formated your file to get PS recognize that the first line are properties of each column we can next apply function [int], measure and so on. I'm wondering then how did you formated you csv file from excel ? So far i'm getting semicolon delimiter for each values but what bothers me the most is that my first line (4 words > 4 properties > 4 columns) is underlined by one continuous line and yours is nicely separated so i assume PS recognize in your file how to separate values. What's the secret?

  • @ABCo-ABMedia

    @ABCo-ABMedia

    Жыл бұрын

    Hi Adnan. So, it sounds like there are two things that could be tripping up Import-Csv here. 1. The fact that you have semicolon delimiters instead of commas. You'll need to add "-Delimiter ';'" to the Import-Csv command so it knows semicolons are separating columns, and not commas, which is what it looks for by default. 2. What do you mean by the underline point? An underline in PowerShell displaying the properties, or in the file? If there's an underline in the file, separating the headings and the values, make sure to get rid of that. Import-CSV doesn't support there being a line below the first with dashes. If you mean in PowerShell, I'm not really sure what you mean; it's hard for me to visualise what's happening over KZread comments.

  • @adnanlaghzaoui2591

    @adnanlaghzaoui2591

    Жыл бұрын

    @@ABCo-ABMedia Hey Alex ty for answering me 🙏 1. Yes i found the -delimeter ";" trick and it works but i assumed that as you are not using this parameter in your video i guess that im missing a point in how you formated your csv file prior to import. Thing is when i export my excel sheet to csv i have these 3 options : - delimiter semicolon - macintosh - DOS How do you set commas as a delimeter? In your excel sheet to specifiy that words are properties? If i export to a txt file i can select too : - delimiter tab - delimiter space I gotta confess im a bit lost but i assume import-csv won't be able to make it from a txt file, isnt it? 2. Sorry if im not clear, gotta improve my english lol. Im talkin about the line of dashes below columns' title ( aka properties , right?). You line got spaces between each columns ie PS can read in the imported file that there are 4 categories of data to process. Mine is one continuous line, so, for example, when i try [int] on one of my properties it doesn't work 🤷 >> ParentContainsErrorRecordException

  • @adnanlaghzaoui2591

    @adnanlaghzaoui2591

    Жыл бұрын

    @@ABCo-ABMedia i finally got something looking like your table if: - i set cell's format as texte - i end each values by a coma - i export in .prn (text file delimiter -space ) But still i can't make the [int] work 😅

  • @ABCo-ABMedia

    @ABCo-ABMedia

    Жыл бұрын

    @@adnanlaghzaoui2591 Is there an error you get from the "[int]" or something? If so, what is it?

  • @ABCo-ABMedia

    @ABCo-ABMedia

    Жыл бұрын

    @@adnanlaghzaoui2591 I missed your first reply, sorry about that! Alright I don't actually know how to get Excel to use commas, I just wrote my CSV file by hand, so I don't anything about the settings on Excel. It would work as a txt file, as long as you set the delimeter right. Import-CSV doesn't care what the file extension of the file is, as long as the data _in_ _it_ is in this structure: Property1,Property2,Property3 Value,Value,Value Value,Value,Value As long as the file is in *that* structure, it will read it. If your file doesn't look like that, just open the text file in Notepad and change it until it does. Then it should work. This is also acceptable: "Property1","Property2","Property3" "Value","Value","Value" "Value","Value","Value"

  • @fawadamin1991
    @fawadamin1991 Жыл бұрын

    $expensiveprocess | where {$_.cpu} | measure -Average CPU $expensiveprocess | foreach {$_.cpu} | measure -Average both shows approx same result for me ..

  • @ABCo-ABMedia

    @ABCo-ABMedia

    Жыл бұрын

    Measure probably has a feature built into it that lets you view the average of only one property so you don't have to filter it down using foreach, but not necessarily every command does have that, which is why the foreach method, it's just a shortcut and you probably don't even need the "Where" in this case, but that doesn't make the other way less applicable as that can be used with any command, the shortcut way may not

  • @jamesthomas8249
    @jamesthomas8249 Жыл бұрын

    PowerShell vs 7.3 can't find csv properties, but PowerShell vs 5.1 Does. is there a problem with the setup for vs7.3

  • @ABCo-ABMedia

    @ABCo-ABMedia

    Жыл бұрын

    What's the exact error you're seeing with PowerShell 7.3?

  • @rahuljadagoud9343
    @rahuljadagoud93432 жыл бұрын

    I need one help... how to import large csv files into SQL server database table using powershell. Any code is there pls share that Sir

  • @ABCo-ABMedia

    @ABCo-ABMedia

    2 жыл бұрын

    I don't have anything I can just send you, it sounds like it'll take a lot of work, but here's a few pointers: - You'll need to use Import-Csv to read the CSV file into a variable - You'll need some way to add rows to a SQL database table, no idea how you'd do this - Once you've figured out how to add a row to the database, you can then use a "ForEach" to go through each row in the CSV file and add it to the database. That's about all I can suggest, it's certainly not a super easy task!

  • @stevesmothers8018
    @stevesmothers80182 жыл бұрын

    Could you explain how you assign the file object to the variable?

  • @ABCo-ABMedia

    @ABCo-ABMedia

    2 жыл бұрын

    I like how you actually thought about that - that's good! I do explain how I did it later on - For now the easiest way for you is probably to just go: $file = ls | Where { $_.Name -eq 'something' } Only one file can have the exact name you put there so you'll just get that _one_ file object in the variable. Technically I did it slightly differently, but you'll learn about what I used later!

  • @Wike120
    @Wike1202 жыл бұрын

    did i completely miss where we went over how insert a file (path) into the command line??

  • @ABCo-ABMedia

    @ABCo-ABMedia

    2 жыл бұрын

    When you use a command like "Import-Csv" and give it a file path, that file path you give it is just a string, a piece of text, stating _what_ _file_ (in the folder you're currently in) you want the command to look at. And the command will then go and do whatever it needs to do from there with the text you gave to work on that file. There's nothing special to it, you're just giving it a bit of text. And you can also give it text like "C:\folder1\folder2", which means it'll go look in that exact folder you've stated instead of the current folder. In the last video I covered using "cd" to change what "folder you're currently in", and as I say, when you want to use a file, you just provide some text to the command. Hopefully that clears it up!

  • @sarahoseghale2511
    @sarahoseghale2511 Жыл бұрын

    I didnt get the import csv 😭 pls someone help

  • @akickedable
    @akickedable2 жыл бұрын

    Sorry if i missed this, can you please provide your tests files ?

  • @ABCo-ABMedia

    @ABCo-ABMedia

    2 жыл бұрын

    What do you mean? The CSV files?

  • @akickedable

    @akickedable

    2 жыл бұрын

    @@ABCo-ABMedia exactly

  • @akickedable

    @akickedable

    2 жыл бұрын

    Its not necessary i guess, personally for me it would be easier trying to follow ur examples using the same csv file , rather then a different one.

  • @ABCo-ABMedia

    @ABCo-ABMedia

    2 жыл бұрын

    @@akickedable Sure, here you are: abco.live/download/2021/students.csv

  • @akickedable

    @akickedable

    2 жыл бұрын

    Thank you so much, great content by the way, i literally got late for work today cause i just had to finish the video :)

  • @poliax7066
    @poliax70663 жыл бұрын

    Haha

  • @noelwilson5253
    @noelwilson52533 жыл бұрын

    still waiting

  • @ABCo-ABMedia

    @ABCo-ABMedia

    3 жыл бұрын

    I'm glad to hear you're enjoying the series enough to want more - thanks for your interest :) Episode 4 has already had the script written, been recorded and been rough edited, now it's just about doing the finishing touches and it will be here! Might even be out today, who knows

  • @noelwilson5253

    @noelwilson5253

    3 жыл бұрын

    @@ABCo-ABMedia thanks bro

  • @ABCo-ABMedia

    @ABCo-ABMedia

    3 жыл бұрын

    @@noelwilson5253 Enjoy the new episode :)

  • @elsultan7
    @elsultan710 ай бұрын

    Everything was working fine till I got to this step 11:33 it gives me this error message: At line:1 char:20 + $students = ForEach {$_.Maths = [int]$_.Maths} + ~ Missing opening '(' after keyword 'foreach'. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : MissingOpenParenthesisAfterKeyword Although, $students variable is working just fine!

  • @ABCo-ABMedia

    @ABCo-ABMedia

    10 ай бұрын

    Hey! The reason it isn't working is you're writing "$students =" instead of "$students |", which is an important difference! With the equals, you're asking PowerShell to run "ForEach" on... Nothing, then take the result of that, and put it into $students, which isn't not quite what we're aiming to do. What we want to do, as in the example, is we want GIVE ForEach all of our students, with all the properties and details on them, and then have it, have ForEach, reach into _each_ _student_ within there and set their Maths itself. Notice the subtle difference. What you wrote is like going up to a window cleaner on the street and saying this "Use this chemical, and put the cleaned windows into this basket". No explanation of _what_ windows to clean, _and_ you don't actually want the windows to be put/_set_ into basket, you just want them cleaned. Same thing with your command, you've told ForEach "Run this code for each....... nothing, and put the result into my students variable", when what you actually want, with the pipe is "Run this code, which sets the maths property, on these given students"

  • @elsultan7

    @elsultan7

    10 ай бұрын

    Thank you so much for this thorough explanation.. You are truly amazing!! @@ABCo-ABMedia

  • @ABCo-ABMedia

    @ABCo-ABMedia

    10 ай бұрын

    @@elsultan7 I just hope it makes sense :)

  • @TheEmperorXavier
    @TheEmperorXavier Жыл бұрын

    So i used the following to concise the code a bit and it worked $students | % {Add-Member -InputObject $_ -MemberType NoteProperty -Name "Totals" ([int]$_.English + [int]$_.Maths)}

  • @ABCo-ABMedia

    @ABCo-ABMedia

    Жыл бұрын

    Yep, the "%" alias is a good way. In the next episode I use exactly that :P

Келесі