PowerShell Arrays Introduction

preview_player
Показать описание
In this video we talk about PowerShell Arrays and how I use them with new-object to create CSV files of data that I can work with in a familiar way. Also covered are hashtables and few other tricks.

Here is the actual PowerShell from the video.

$Array = @()

$Processes = Get-Process

Foreach($Proc in $Processes)
{
If($Proc.WS/1mb -gt 100)
{
}
}

$CSVImport = @()

#Just want to look at it in a prettier way?
$CSVImport | Format-Table -AutoSize

#Other tricks to keep in your pocket
$CSVImport[1].ProcessName
Рекомендации по теме
Комментарии
Автор

Shane, loving the videos on PowerShell! You're a good teacher!
I was wondering if you could do a more advanced video on Arrays? I'm stuck, I've built on Array of Server Names from a XenApp command, then I have a ForEach statment running against that Array of Server Names, but I'd like to know how to Add additional information/psobjects into this existing array (the new information gathered from the ForEach statement), is this possible?

Biska_Wolf
Автор

I bet you can't find such a friendly trainer anywhere ever.. Shane is all smiles and all brains 👍

allanrabindran
Автор

I always learn so much as you do your script walks/PowerShell parsing. Thank you Shane!

Galileok
Автор

Thanks so much for making these vids. I am forever finding myself involved in migrations/implementations and don't have the powershell skills to do the kind of thing you're demonstrating here. Much appreciated!

bakeruk
Автор

I appreciate your high quality work and professionalism. Thank you sir.

jime
Автор

Your vids are better than the Udemy courses that I paid $$ for!! Thanks!

briancrane
Автор

You`re the best teacher I found. Subscribed. Please keep making video`s. :) Thanks!!

freke
Автор

You rock so much, Shane. I'm having tons of fun while learning PS with your videos. Thanks!!

Bule
Автор

Great job man 👌👌 crystal clear and very precise

prabur
Автор

Loving your videos, you are a great teacher, i'll be coming back for more, thats for sure

THHUTTZ
Автор

Your videos are awesome, really well explained! . Many thanks for taking the time and effort to publish them.

luisolias
Автор

As always, thank you for another great video. I follow a lot of your more recent PowerApps stuff, which has been brilliant. But I also need to get to grips with PowerShell for managing Teams permission policies and I was getting a bit lost in PowerShell for Teams. The ForEach and ForEach-Object and this Arrays video has been so helpful. I work at a school and we have gone heavily into Teams for remote learning. I need to make sure Teams policies are correctly set for students and staff and so if you ever feel inspired to make a video about Microsoft Teams Policy settings in PowerShell, that would be amazing.

nharzic
Автор

Like that you're using ps ise. Having multiple tabs means each step of the show can be named along the top. Pretty cool.

timmurray
Автор

I have already watched the first two videos. Thanks!! Excellent way to teach PS. Now in this third video, in minute 5 you use as example (foreach $pp in $processes) and thereafter you list $proc (instead of $pp) and you were able to show the property "ws" for $proc. Should it be for $pp instead of $proc?. Or I missed something there?. Again, thanks. After seen a lot of PS videos, these are among the best.

lautarob
Автор

I got really curious how come after importing the CSV you could still get values by the same property names until I looked back at 11:00 and saw they were exported like column names in the CSV file. This shouldn't be a shock to me since I did something similar in Java, but seeing this done in PowerShell so easily just blew my mind.

ricsmith
Автор

Thanks for the video Shane. Starting to learn powershell with your videos. I have a question, Might be a stupid one, What is the need for creating a new object? Can't we just append the array with properties without needing to create an object?

fayasputhukkudi
Автор

Awesome, cannot wait to watch and learn, Thanks Shane!

NancyRileyNuniverse
Автор

Great Videos on PS !!! Wonderful !!! THANK YOU!!!

MichaelToub
Автор

Cool video!
Just a thought from one dev to another: when an array exceeds a certain amount of indices, the method of using the ‘+=‘ operator in an iteration will, if I understand PowerShell array objects correctly, quickly allocate much unnecessary memory due to the fact that PS arrays are immutable, thus this will create a new mirrored array object in memory just with this new index.

An iteration of n times, will then result in n number of array objects created in the background with one increment each, where only the last one is complete. correct me if I’m wrong here - this is what I’ve learned about this data structure in PowerShell.

To combat this and to have an object that behaves more like a List object in Python, when I iterate and append an array I usually instanciate an arraylist or [int] depending on usecase) to have a mutable array which nicely adds with the .Add() method.

I see your example as trivial between these two approaches but imagine a scenario with sublists of thousands of indices on a core server where ram == money.

How goes your thoughts?
/ PS isn’t my ‘native tongue’ if you catch my drift.

simonolofsson
Автор

I like the content and when some one provides the script example in the video description.

Not a PowerShell expert and here to learn like you all. Sorry if i did not understand this correctly, If any one can clarify me this doubt. Instead of creating the array and exporting the data in CSV like the example in the video, The same can be achieved by using a 1 line command without an Array:

Get-Process | Where-Object {$_.WorkingSet -GE | Select ProcessName, Workingset | Export-Csv -Path C:\Temp\mydata.csv

So i am still not clear on the purpose of using an array from this example.

gautamr