PowerShell ForEach-Object

Поделиться
HTML-код
  • Опубликовано: 20 авг 2024

Комментарии • 89

  • @Corrado49
    @Corrado49 2 года назад +1

    Thanks for this video, almost five years later continues to be very useful!

  • @gregorymendyka
    @gregorymendyka Год назад +1

    Thanks for your time, Shane. Greetings from Scotland.

    • @ShanesCows
      @ShanesCows  Год назад

      Thank you! Greetings right back at you. 😎

  • @valentinebarbier6156
    @valentinebarbier6156 3 года назад +4

    Thank you for these PowerShell videos! I've really been struggling and afraid of scripting. You made it way easier for me to get into, and i'm actually enjoying working on that! Thanks again :)

    • @ShanesCows
      @ShanesCows  3 года назад +1

      PowerShell is so much fun. Enjoy. 😎

  • @EdResleff
    @EdResleff 5 лет назад +1

    You're making me really like PowerShell... again! I got away from using it and then had to jump back in with some intrepidation and a healthy dose of trepidation in my current gig. Am faced with learning a PS script that is overloaded with C++ and C# coding characteristics, but also using some Hungarian notation that has me pulling my hair out... what little I have left. However, your explanations are so calming (and at times a little humorous) that I'm able to sigh and say "This ain't so bad" and I've actually played around with your last ForEach-Object example in this video to get some good stuff out of my script... Yay..! Awesome job on the video!

  • @CEL2815
    @CEL2815 3 года назад +1

    Hey Shane, thanks so much for making these videos. I've read books on PowerShell, but there's NOTHING like learning visually. Your videos are simple to understand, and follow along and makes it easier for me to WANT to learn PowerShell. Thanks again. If I come across topics I want to learn more about, I will send a comment to see if you can make a video. Have a great day!

  • @KSR86
    @KSR86 6 лет назад +9

    HI Shane,
    Your tutorials are very informative and I am learning out of it. Thank you!!!

  • @liondk1589
    @liondk1589 3 года назад +1

    These videos are helping me so much for my exams THANK YOU!!!

  • @stefanspinu8784
    @stefanspinu8784 5 лет назад +2

    Man, you're great. Too bad this video has just over 100 likes - it's worth millions. Keep up the good work!

    • @ShanesCows
      @ShanesCows  5 лет назад

      Your comment is worth millions to me. Thanks! 😎🤑

  • @SCADASupportPh
    @SCADASupportPh Год назад +1

    @shaneyoung is awesome, Shane is cool.... you forgot to mention "Shane is good at educating people". I never get tired of watching these PS script presentation of yours.
    Thank you Shane for sharing! GOD Bless!

    • @ShanesCows
      @ShanesCows  Год назад

      Very kind of you. Have a great weekend!

  • @skfarid9069
    @skfarid9069 4 года назад +1

    Your tutorials are really awesome and very informative .Thanks

  • @swapneshgodkar4192
    @swapneshgodkar4192 4 года назад +1

    I got you as my first Powershell instructor.. :)

  • @allanrabindran5695
    @allanrabindran5695 3 года назад +2

    East or West Shane is the Best ❤️

  • @Bule2805
    @Bule2805 5 лет назад +3

    Hi Shane! Great video as always, I'm learning a lot and having so much fun. Just a quick note: I know this video was made almost two years ago and I'm not sure whether Excel or PowerShell new versions have anything to do with this, but I had a bit of a brainer with the import-csv table format as all data was displaying in strings separated by semicolons, merging the information from columns A, B and C, instead of the nice and neat table you are showing. Got a bit frustrated until I figured out I was missing the -delimiter ";" at the end of line 1 (and 3, subsequently). Not sure if it has happened to anyone else following your vids on 2019, but whatever the case, you are a Rockstar and I thought you might want to know in case the feedback is interesting enough for other people. Keep up the amazing work and thank you again!

    • @ShanesCows
      @ShanesCows  5 лет назад

      Awesome. Thanks for sharing.

    • @jakubberger5399
      @jakubberger5399 3 года назад

      For me worked -UseCulture at the end of the line (PowerShell 7.1).

  • @aynellrodriguez7348
    @aynellrodriguez7348 3 года назад +1

    Thanks Shane, very useful and easy to understand..

  • @cool24a
    @cool24a 6 лет назад +7

    You have the best intro!

    • @ShanesCows
      @ShanesCows  6 лет назад +2

      Thank you! You don't know how much that means to me. I spend way too much time trying to get the first minute right to get people to watch the whole thing.

    • @omerfarukerkul1197
      @omerfarukerkul1197 5 лет назад +1

      @@ShanesCows Heeeeere is our intro 👉👉

  • @jfreck
    @jfreck 5 лет назад +1

    Great another awesome topic I'm gonna be able to use. Hoping to use for remote server functions. Being able to distingush the whole "DEV" group will be handy. Thanms

  • @lauramoney1533
    @lauramoney1533 6 лет назад +3

    Thank you for the great tutorial!

    • @ShanesCows
      @ShanesCows  6 лет назад +1

      You are welcome. Thanks for watching and I am always open to new video ideas.

  • @ashmsport1562
    @ashmsport1562 6 лет назад +2

    Thank you Shane. Great videos!!!

  • @shaktisingh8752
    @shaktisingh8752 5 лет назад +3

    Sir, Really helpful.

  • @Aarvens
    @Aarvens 5 лет назад +1

    Great instruction, great video. Thanks!

  • @talosvalcoran4714
    @talosvalcoran4714 4 года назад +1

    Good video, Shane. Thank you.

  • @jamesblair110
    @jamesblair110 5 лет назад +1

    If you don't get the colored text to work, be sure to save .csv as CSV-UTF8. Regular CSV Comma delimited won't work. I'm using office 365/2016, so may be a quirk.

  • @billyridgeway4074
    @billyridgeway4074 6 лет назад +2

    Thanks you, great video.

  • @taseenridwansvlog3965
    @taseenridwansvlog3965 2 года назад

    Hey Shane, can you show how to import bookmarks,favorites from chrome to edge using powershell

  • @sithmaster56a
    @sithmaster56a 6 лет назад +1

    hi Shane, have you covered error catching in one of your PowerShell videos as I have tried to learn this in the past and I’m having a real hard time getting my head around it.
    also really appreciate these videos they've shown me a few ways of doings things easier in my scripts.
    thanks

    • @ShanesCows
      @ShanesCows  6 лет назад

      Sorry. I haven’t. It is a topic I have always wanted to tackle and just have not.

  • @srinivasanrajagopalan3140
    @srinivasanrajagopalan3140 3 года назад +1

    Hi shane..can you make a video for rest api through powershell

    • @ShanesCows
      @ShanesCows  3 года назад

      I haven't done much with that. Sorry.

  • @SuperKishore20
    @SuperKishore20 5 лет назад +1

    Shane is Awesome

  • @mjackstewart
    @mjackstewart 4 года назад +1

    I’ve always been confused by this. If the pipe sends three objects to the next commandlet, why is it necessary to iterate over them in a foreach-object?

    • @ShanesCows
      @ShanesCows  4 года назад +1

      Because you want to run the cmdlet 3 times, once for each object.

  • @pa1089
    @pa1089 4 года назад +1

    Hello Shane,
    Thank you for the videos.
    I am working on a New user onboarding script and stuck at adding users to the security as well as distribution groups based on location and department.
    Basically i have a CSV with Location,FirstName,LastName,Department and using IF statements to move users to the location based on the CSV file and able to create users. I am using the same Logic using the IF statement to add users to the security group based on location and department but seems the script only works just one user and remaining untouched. Below is the code for your reference:
    #Adds user into Department specific security groups
    If ($Dept -eq 'IT')
    {
    Add-ADGroupMember -Identity "IT Security Group" -Members $SAMAccountName
    }
    ElseIf ($Dept -eq 'Accounts')
    {
    Add-ADGroupMember -Identity "Accounts Security Group" -Members $SAMAccountName
    }
    #Adds user into Location specific security groups
    If ($Location -eq 'Location')
    {
    Add-ADGroupMember -Identity "Location Distribution Group" -Members $SAMAccountName
    }
    ElseIf ($Location -eq 'Location 2')
    {
    Add-ADGroupMember -Identity "Location2 Distribution Group" -Members $SAMAccountName
    }
    Can you please advise what am i doing wrong here as i have serached online for long hours and could not make this to work.
    Appreciate your help on this.

  • @MohitSharma-if1bg
    @MohitSharma-if1bg 4 года назад +1

    Hey Shane, great video. Really helped me understand the concept of manipulating each row in a CSV and assigning a number value for whatever purpose you need it for. I have a question, how would I manipulate each character from a specific row? For example, in one row I need to evaluate a computer's specs based on a specific number character in the 20th position from the left of the row. If that 20th position character is an i5 (5 being the important piece here) then i do something... how do I read that 20th position of the row. Hope that makes sense....

    • @ShanesCows
      @ShanesCows  4 года назад

      Look for my video on string manipulation

  • @atexnik
    @atexnik 4 года назад +1

    If I change the value after -gt to, something else, say, 500 or 5000, then the write-host statement is not being executed. I think, the reason behind it is that the ObjectPropertyNumber is of String type. I wish you added a step to convert it to integer.

    • @ShanesCows
      @ShanesCows  4 года назад

      Sorry it didn’t work for you.

    • @atexnik
      @atexnik 4 года назад

      @@ShanesCows it's not my fault, the object is string. You can't compare string to integer.

  • @elybuendia64
    @elybuendia64 4 года назад +1

    Hi Shayne I need help on comparing 2 csv files and displays their differences...ty

    • @ShanesCows
      @ShanesCows  4 года назад

      Sorry I don't have a video on that.

  • @powerbi-amitsrivstava4451
    @powerbi-amitsrivstava4451 3 года назад +1

    Hi Shane,
    Nice video :)
    I need to retrieve Power BI data such as workspace, dataset, dataflows, reports, users etc.
    Either, this data will come via using one command OR with multiple command yields individual data for every entities with proper foreign key relation ship between them but in either case i dont want to pass any parameter to PowerShell command to retreive result.
    OR is there any other way out to retrieve such required result.
    Thanks
    Amit

    • @ShanesCows
      @ShanesCows  3 года назад

      I am sorry, I don't know.

  • @jolenec7159
    @jolenec7159 4 года назад +1

    Thanks, Shane! Is there any way to compare the contents of multiple files (two folders, different versions)? Compare-object seems to only provide the basic info of different file names.

    • @ShanesCows
      @ShanesCows  4 года назад

      I am not sure. 😑 I haven't tried that one before.

  • @skfarid9069
    @skfarid9069 4 года назад +1

    Hello Shane,
    I really need a quick help from your side as I need to copy/clone Azure Data Factory entities like Linked services,Datasets, Piplines, Triggers from one environment to another using Powershell only so that it will take value dynamically.The reason is that some of these pipelines may change and it is hard to keep up with changes.So, can it be possible to get all the data from data factory using power shell and then can make a clone of it, because if we update a pipeline, it would be great to copy and paste the logic.
    It will be of great help if any assistance is provided from your end.
    Thanks in advance !!! Awaiting for your valuable reply.

  • @peex1986
    @peex1986 2 года назад

    Hi There, good effort but in the first 6' , I don't see anything clearly ....Plz clear your camera. Regards PE

    • @ShanesCows
      @ShanesCows  2 года назад

      Hey, sorry you are having troubles. Must be your internet or RUclips settings. I double checked and the video shows in hi definition for me.

  • @ML-356
    @ML-356 6 лет назад +1

    Shane I'm having trouble with powershell, doing the same as above, but I want to send mail message for each line from my CSV.
    Wondering if you could help?

    • @ShanesCows
      @ShanesCows  6 лет назад

      What have you tried? Send-mailmessage should be all you need.

  • @userpodcast7350
    @userpodcast7350 6 лет назад

    Could you program how to program our script if we had a column called Date and we would like to sort our array in Powershell regarding the values in the cells of Date column? Great videos! Like!

    • @ShanesCows
      @ShanesCows  6 лет назад +1

      Do you want to sort the array while you are working with it in PowerShell or save it to a CSV file that is ordered by date?

    • @userpodcast7350
      @userpodcast7350 6 лет назад

      It's a ledger and I'd like to have an input csv completly rearranged by the date column and save it to an ouput csv file. I guess it involves parsing every value in the cell date to an object date but then I dont know how to do it. Could you please elaborate the solution! Thank you for answering! Your videos are very explanatory! Best regards.

  • @sulyluna7563
    @sulyluna7563 5 лет назад +1

    Hi Shane, I am having a PS coding mental block where I can't figure out how to change the values of a column in a csv file and then output the updated csv. Essentially, I want to take the column "group owner" where the names are listed in displayname format (i.e., "John Smith") and convert them to their respective SamAccountName (i.e., jsmith) and then export the updated csv that now lists all groupowners in SamAccountName format. I've seen solutions online where the script takes the first and last name and "creates" SamAccountNames but that is not a solution in my case because at our company a user's samaccountname is not necessarily first initial+lastname because there are several people that would end up with the same samaccountname in AD which is not acceptable. My script would need to contain the code "$SamAcctName = Get-ADUser -filter (Name -like "$_.groupowner) | Select Samaccountname" to get the owner's actual samaccountname.
    My issue is that although my for-eachobject loop is processing each entry of the "groupowner" , it is not saving the person's samaccountname into the variable $SamAcctName.
    Instead, the output for $SamAcctName is blank. Below is my code. I'm hoping that you can spot what I am doing wrong and provide me with the correct code. Thank you in advance.
    $csv = Import-Csv C:\Temp\TestCsv.csv
    $csv | ForEach-Object {
    # sending current value of $_.groupowner to host screen as a control
    Write-Host "The group owner is:" $_.groupowner
    # grabbing this group owner's Samaccountname from AD and assigning that value to the variable $SamAcctName
    $SamAcctName = Get-ADUser -filter 'Name -like "$_.groupowner"' | Select SamAccountName
    # Here is my attempt at replacing the display name of the group owner with his Samaccountname (username)
    # by assigning the $_.groupowner item the value contained in $SamAcctName
    $_.groupowner = $SamAcctName
    Write-Host "This group owner has samaccountname:" $SamAcctName
    }
    Export-csv C:\temp\TestCsv.csv -NoTypeInformation

    • @ShanesCows
      @ShanesCows  5 лет назад

      Not sure. Sorry

    • @sulyluna7563
      @sulyluna7563 5 лет назад

      No worries, I spotted my error and fixed it. Thank you for looking into it though. Enjoy your labor day weekend

  • @dabeebinc6508
    @dabeebinc6508 4 года назад

    I have a task I need to do can you help me

    • @ShanesCows
      @ShanesCows  4 года назад

      Sorry I am behind on comments. Hope you got it figured out.

  • @kipster-ll6po
    @kipster-ll6po 6 лет назад

    Thanks so much! I am really enjoying this playlist. You are very likable, and easy to learn from. Question about this video: From 13:55 thru 14:00, why didn't "this object is bigger than 1000" get written for every iteration of the loop? Since the variable was NOT reinitialized for the second run, it ended up containing 22,200. Therefore, during that 2nd run, that line of text should have been written to the screen three more times. No?

    • @ShanesCows
      @ShanesCows  6 лет назад

      It does. If you watch a few seconds earlier 13:53 I reran the lines so the screen flashes and you can see all three lines are written to the screen again. It happens quickly but you are correct, the screen does get written again as I am making the variable 22,200.

    • @kipster-ll6po
      @kipster-ll6po 6 лет назад +1

      I believe you are talking about the lines that say, "The name of the object is..." However, I was talking about the line that says, "This object is bigger than 1000." Anyway, I eventually figured out my mistake: The if statement is evaluating the value contained in the ObjectPropertyNumber property, NOT the value contained in the $TotalOfNumberColumn variable. Anyway, thanks for the reply -- I know your time is valuable.

  • @RyanHeitz
    @RyanHeitz 2 года назад

    Thanks for another helpful video, I just subscribed! Would you consider making a video about PS functions like this one ruclips.net/video/BdfVsoMVz8g/видео.html but without so much jargony, computer sciencey language? I really need learn what is being taught in that lesson but it's a bit advanced, assumes some knowledge, and is targeting PhDs in computer science. :-)