Getting started with the PowerShell If Statement

Sdílet
Vložit
  • čas přidán 20. 08. 2024

Komentáře • 46

  • @Corrado49
    @Corrado49 Před rokem +3

    These videos continues to be useful for me!

  • @oliverjeffries8532
    @oliverjeffries8532 Před 4 lety +1

    You are fantastic! Been having so much trouble with my IF ELSE statment and you have shown me a much simpler way to get a better result! thank you

  • @gilgameshxg
    @gilgameshxg Před 2 lety +1

    Great Stuff! Thanks for breaking it down to easy-to-understand terms/steps for someone starting out in PowerShell.

  • @monkeybum1984
    @monkeybum1984 Před 2 lety +1

    Hi Shane, I'm really enjoying your powershell series. Thanks!

  • @JesterV
    @JesterV Před 3 lety +1

    Shane you are better than my teacher, thanks for your amazing job, I got subbed right now
    Cheers from Barcelona

  • @lahernandezs
    @lahernandezs Před 6 lety +3

    Shane......you are AWESOME!!!! thank you very much for sharing so interesting videos like these!

  • @SJ-rp1kf
    @SJ-rp1kf Před rokem +1

    Thanks for the video. Much appreciated

  • @justme-iz7ec
    @justme-iz7ec Před rokem +1

    fantastic, excellent, superb

  • @scottdimond7919
    @scottdimond7919 Před 6 lety +3

    Thanks Shane for another great video. I particularly like your error handling routine. Nice and simple. :)

  • @hassanmalik7505
    @hassanmalik7505 Před 6 lety +2

    Very informative. Good section on comparison operators!

  • @AllenAndersonTaylor
    @AllenAndersonTaylor Před 4 lety +2

    Hey man, thanks for these videos. They are really helping me learn PS.

  • @GoingMod
    @GoingMod Před 3 lety +1

    Thanks, this helped me with me text based RPG game in PS!

  • @DM-py7pj
    @DM-py7pj Před 4 lety +1

    Another great one. Thank you.

  • @luishiguita4779
    @luishiguita4779 Před 4 lety +1

    Very helpful, thanks.

  • @NickSlaughterDude
    @NickSlaughterDude Před 4 lety +1

    Thanks Shane!

  • @tiagobial4
    @tiagobial4 Před 4 lety +1

    OMG so helpful thanks for the video.

  • @GixxerDaveNeo
    @GixxerDaveNeo Před 5 lety +1

    Great videos! I have a question about alias is there a way to replace all the alias’ in code auto magically, or a way to convert?

  • @picnicsinspace198
    @picnicsinspace198 Před 5 lety

    Please help me with these questions I'm having a hard time figuring them out:
    1-Write the PowerShell code necessary to prompt the user to enter a number and store that value in a variable called $userPIN using a datatype of Int32.
    2-Check if the userPIN entered is positive and if not print out an error message.
    3-Check if the userPIN entered is at least 4 digits long and if not print out an error message.

  • @zubena13
    @zubena13 Před 6 lety +2

    i have made this $names=@('Audiosrv', 'BFE', 'BITS', 'Dhcp', 'Dnscache', 'DNS')
    and then made this foreach($item in $names){get-service $item|select displayname, name , starttype, status}
    i dont have service named DNS so i need to implement if statement that it could print that nonexisting service into a custom named .csv file and all others that are found in the list i need to put those to in seperate .csv file.
    if you will reply me fast i would be grateful dude.

    • @ShanesCows
      @ShanesCows  Před 6 lety

      You would want to put in a Try and Catch. That way if there is an error it would drop out and do your steps for logging the missing services.

  • @Promos321
    @Promos321 Před 5 lety +1

    I'm having trouble with validating the value when it belongs to the status of a service (opposite to a Where-Object command where no matter what, it's always valid - Argh).
    In the below example, I would like it to output the word 'talk' to screen when the IF is valid.
    As I show in my example below, the variable value currently is "stopped", but IF does not see it so.
    Where am I going wrong here?
    ***********************************
    PS C:\Scripts> $Service
    Status Name DisplayName
    ------ ---- -----------
    Stopped WebClient WebClient
    PS C:\Scripts> If($Service -eq "Stopped") {'talk'}
    PS C:\Scripts> If($Service -eq 'Stopped') {'talk'}
    PS C:\Scripts> If($Service -eq 1) {'talk'}
    PS C:\Scripts> If($Service -eq 4) {'talk'}
    PS C:\Scripts> If($Service -eq Stopped) {'talk'}
    At line:1 char:16
    + If($Service -eq Stopped) {'talk'}
    + ~
    You must provide a value expression following the '-eq' operator.
    At line:1 char:17
    + If($Service -eq Stopped) {'talk'}
    + ~~~~~~~
    Unexpected token 'Stopped' in expression or statement.
    At line:1 char:17
    + If($Service -eq Stopped) {'talk'}
    + ~~~~~~~
    Missing closing ')' after expression in 'If' statement.
    At line:1 char:24
    + If($Service -eq Stopped) {'talk'}
    + ~
    Unexpected token ')' in expression or statement.
    + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : ExpectedValueExpression

    PS C:\Scripts>
    ***********************************
    Thanks for the help in advance.

    • @Promos321
      @Promos321 Před 5 lety

      Found it.
      As the Get-Service has 3 values (Columns: Status - Name - DisplayName), I needed to specify which one it was to look at. I was assuming that by default it would look at the value for Status, but not so.
      Solution syntax was:
      If($Service.Status -eq 'Stopped') {'talk'}

    • @ShanesCows
      @ShanesCows  Před 5 lety

      Hey. I am not sure. Sorry

  • @anthonyfreeman7807
    @anthonyfreeman7807 Před 6 lety +1

    NAAAAAAT! sorry, that was weird. hahahaha i laughed so hard in the office

  • @picnicsinspace198
    @picnicsinspace198 Před 5 lety +1

    I'm having trouble is there an e-mail I could use to contact you to ask you a few questions about my script ?

  • @joevanynguyen9691
    @joevanynguyen9691 Před 5 lety +2

    I need PowerShell tutor can you help me, we can work something out.

    • @ShanesCows
      @ShanesCows  Před 5 lety

      I don't do PowerShell classes anymore. :( Sorry.

  • @justme-iz7ec
    @justme-iz7ec Před rokem +1

    I appreciate professionals making content. That's why I paid for CZcams Premium. I do wish your introduction was not so verbose.

    • @ShanesCows
      @ShanesCows  Před rokem

      Sorry. It got turned down quite a bit in the later videos.

  • @tathineos
    @tathineos Před 3 lety

    I think you should better consider that people who are following powershell lessons, are expected to have a minimum experiance of at least one easy programming language. Powershell is not the kind of topic for starters in programming language to learn how an if statement works. Powershell is not good nor suitable to reach their needs.
    I believe that such basic issues in programming syntax and further details of the if statements, arrays, variables etc basics, are destructing the purpose of the most of the followers of your lessons, becasue they miss some powershell semantics while they are jumping time-bar during each lesson.
    I guess a short example for each of the basic statements, emphasising the most common differences, in a single lesson, would be enough to explain for the followers who can really benefit these lessons.