Powershell Basic Scripts, before we learn Powershell Basic scripts, first we need to understand the script execution policy. What does it mean, Powershell console or window has 4 main execution policies for any script to run.
Here are the execution policies.
if the is execution policy is set then all the scripts run, however, all scripts are signed by a trusted publisher, including the scripts that you run on your local machine.
This is default execution policy, it allows only individual commands to run, it doesn’t allow the scripts.
This is a default execution policy for server-based operating systems. All scripts are allowed to run.
If you set this execution policy then you need to have any digital signature on the scripts that you run on your local machine. However, if you want to run the scripts download from the internet then it requires a digital signature from a trusted publisher.
If you have set your Powershell execution as Bypass then nothing is blocked and no warnings, all scripts are allowed to run.
Let’s work on the commands now, to get what policy is on your machine currently use get-executionpolicy.
Let’s change the execution as remote signed, I recommend to use this policy for good security and compliance and again you can easily change the execution policy as per your need anytime!
write-host “I’m learning Powershell on techdiip.com”
let’s find a service status
There is a cmdlet that we use to retrieve service status is….
get-service -Name AdobeFlashPlayerUpdateSvc
If you want to see the Methods and Properties of this command then we have to use…
get-service | get-Member
on the result screen, you get the below.
Let’s how we can get help from powershell.
There is command get-help that gives all the information about any command available in the Powershell.
get-help | format-table
The above command gives detailed information on how format-table is useful.
|1||.PS1||This is a powershell extension and all powershell files saved with this extension and opened only in powershell.|
|2||Cmdlets||The commands available in the powershell we call cmdlets, we have to import modules to get with respective tasks or application automation.|
|3||Confirm||This gives a pop-up asking us to confirm while executing the code or script|
|4||Debug||This command gives us debug information, this is helpful for troubleshooting the script.|
|5||ErrorAction||This is the default variable available in the powershell and most useful when you dealing with errors.|
|6||ErrorVariable||This is a default variable and holds errors information of powershell code|
|7||Functions||Powershell functions are the most lightweight form of powershell command, it’s a grouping of code runs against each object defined (within that code) in the script block and performs the specified action. Powershell functions help the administrator to create reusable code which acts as powershell cmdlets.|
|8||OutBuffer||This command gives the object count and uses when you are dealing with the pipeline.|
|9||OutVariable||This command gives us the information of a variable which holds output information|
|10||Scripts||The powershell scripts extension ends .ps1 and we can’t directly open it, we have to edit and run in powershell interface itself.|
|11||Verbose||This command gives us detailed information of a task while executing the script.|
|12||What if||This is a command (cmdlet) that gives information about what happens if you execute code or command.|
Thank you for reading this article, if you have any questions please let us know.
Thank you for visiting my site, please make sure you have tested this script in our lower environment before you run in production.