PowerShell Day 4

PowerShell Day 4


Day #4 of #powershelltopicinaweelatluncheschallenge

Hi guys ,???? as we all know PowerShell created by Jeffery Snover on 14th November,2006. PowerShell is a task automation and configuration management program from Microsoft which consist of common line shell and its associated scripting language. Today we're combining two topics. They are PowerShell input and output and PowerShell errors.

PowerShell Input and Output

Your PowerShell code will often need to evaluate some type of input. Did you know that you can use the output of cmdlet for the input of your PowerShell functions? You can also perform various functions based on the generated inputs depending on what a cmdlet returns. These varieties are:

  • Perform functionality based on dynamic input
  • Run cmdlet
  • Use output as your input

PowerShell input from web

Here we use invoke-webRequest to retrieve web content from PowerShell. As a result ,the output content from the above cmdlet is in JSON. JSON is a structured data ,we can take control and convert it to native PowerShell objects. How can you go about using output from an output?

Ways to generate input ;

1.Leverage cmdlet output as input

  • Email yourself the top 3 PowerShell posts of the day.
  • Send yourself a text message with the top post of the day
  • Display the top 10 posts of the day when you login

2.Using read-host input

The read-host cmdlet reads a line from the console (standard input). IThe read-host cmdlet can be used to

  • Prompt a user for input
  • Prompt to secure data such as passwords
  • Save the input as a secure string

One astonishing part is that the read-host cmdlet has a limit of 1022 characters ,it can also accept as input from a user. For example;

  • Save console input to a variable

For the diagram below, when a value is entered and the key is pressed, the value is stored in the age variables

  • Mask input as a plain string

When the Enter key is pressed, the value is stored as a plaintext string object in the $pwd_string variable.

Add alt text

PowerShell Output

If you desire to display results back to the console or you would like to generate some type of Powershell output. There are few ways to accomplish this trade.

  • Write-host

Write-host can output customized strings to the console ,you can customize the output by controlling the start of a new line or NoNewLine can also set up the foreground and background color.

It is also capable of string output, so you need to do is to make sure you are giving it a string ,if not write host will do its best to take in some type of output but not the expected results.

PowerShell Error-types

A program error is defined as an error which occurs during the development or encoding of a computer program, software or application ,which when in operation ,result in a malfunction of incorrect operation of a computer network. Hence if there is an error the software won't continue until the issue is corrected .One thing about PowerShell is that it doesn't behave the way and may terminate errors .

Terminating errors

Terminating errors is an error generated by script ,functions or commands you create and halts the execution of the script so that the commands in the next lines can't be executed.

Case where you want to force PowerShell to terminate ;

  • The error warrants stopping all further action
  • You want to trap and evaluate the error – possibly performing various actions based on the error information
  • You want to trap the error and hide it from the user – providing a more user friendly message

ErrorAction

?Common parameter that tells PowerShell what action to take when it encounters an error. The truth is, you’re always using the ErrorAction parameter. You’re just using the default setting when you don’t specify it, which is continue. Continue will display the error to the console and keep processing.

One thing I like about PowerShell is that it makes you smarter .??

#powershelltopicinaweekatluncheschallenge

#educ8africa ghana

#eccouncil

#cybersecurity

#certifiednetworkdefender

#Day4

Alexandra Boateng

Educ8Africa Ghana

Brian Y. Woyome

Newman Mortey


No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Credits:


https://bit.ly/3WTXCN1

要查看或添加评论,请登录

Gladys Ivy Mensah的更多文章

  • #My90DaysNetworkDefenseDiary

    #My90DaysNetworkDefenseDiary

    Day #1 of #My90DaysNetworkDefenseDiary We haven't spoken in a very long time; I briefly disappeared ??. I'm thrilled to…

  • User Identities

    User Identities

    #useridentities What Is User Identity? It is an entity used to identify a user on a website, in software, on a system…

  • Basic Networking

    Basic Networking

    Hi guys #120HoursofBasicNetworking An IP address is a unique address that identifies a device on the internet or a…

    1 条评论
  • Day 1

    Day 1

    Day #1 of #120hoursofbasicnetworking Hey guys we are starting our basic networking journey. First of all a network is a…

  • PowerShell Modules

    PowerShell Modules

    #powershelltopincinaweekatlunchesextensionchallenge PowerShell module A PowerShell module is a .psm1 file (a script…

  • PowerShell Remoting

    PowerShell Remoting

    Day #6 of #powershellweekchallenge Remoting Did you know that remoting is a technology that allows a program to…

    2 条评论
  • Day 6

    Day 6

    Day #6 of #powershelltopicinaweekchallenge.Hey guys its day 6 of our PowerShell discussion.

  • PowerShell day 5

    PowerShell day 5

    Day #5 of #powershelltopincinaweekatluncheschallenge Hey guys???? its another day of our PowerShell lesson ,today we…

    3 条评论
  • Day 3

    Day 3

    #powershelltopicinaweekatluncheschallenge #educ8africa ghana #eccouncil #cybersecurity #certifiednetworkdefender #Day3…

  • Day 2

    Day 2

    #powershelltopicinaweekatluncheschallenge #educ8africa ghana #eccouncil #cybersecurity #certifiednetworkdefender #Day2…

    1 条评论

社区洞察

其他会员也浏览了