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.
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.
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.
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'}
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.
These videos continues to be useful for me!
Awesome Pedro!
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
Awesome!
Great Stuff! Thanks for breaking it down to easy-to-understand terms/steps for someone starting out in PowerShell.
Very welcome!
Hi Shane, I'm really enjoying your powershell series. Thanks!
Glad you like them!
Shane you are better than my teacher, thanks for your amazing job, I got subbed right now
Cheers from Barcelona
Wow, thanks!
Shane......you are AWESOME!!!! thank you very much for sharing so interesting videos like these!
Thanks for the video. Much appreciated
My pleasure!
fantastic, excellent, superb
Thanks. 😎
Thanks Shane for another great video. I particularly like your error handling routine. Nice and simple. :)
Very informative. Good section on comparison operators!
Hey man, thanks for these videos. They are really helping me learn PS.
Glad to help. 😀
Thanks, this helped me with me text based RPG game in PS!
Fun!
Another great one. Thank you.
Thanks!
Very helpful, thanks.
Glad to help. 😀
Thanks Shane!
Happy to help Nick
OMG so helpful thanks for the video.
Glad to help. 😀
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?
Not that I know of. 😑
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.
Replied to the other comment
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.
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.
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.
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'}
Hey. I am not sure. Sorry
NAAAAAAT! sorry, that was weird. hahahaha i laughed so hard in the office
I'm having trouble is there an e-mail I could use to contact you to ask you a few questions about my script ?
Check out BoldZebras.com
I need PowerShell tutor can you help me, we can work something out.
I don't do PowerShell classes anymore. :( Sorry.
I appreciate professionals making content. That's why I paid for CZcams Premium. I do wish your introduction was not so verbose.
Sorry. It got turned down quite a bit in the later videos.
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.