PowerShell is a powerful command-line and scripting tool developed by Microsoft to manage and automate tasks on Windows systems. Using PowerShell, you can easily automate routine tasks and manage various operating system components such as file systems, registry, network, services, and more. PowerShell article covers all aspects of working with this tool, from its basic principles and concepts to more complex tasks such as deploying and managing cloud environments. You’ll learn how to create, run, and debug PowerShell scripts, and how to use powerful features like modules, objects, and variables.
Moreover, the article covers various examples of using PowerShell to manage files and folders, the registry, services, networking, and other Windows components. She also looks at using PowerShell in conjunction with other technologies such as Active Directory, Exchange, and SharePoint. Finally, the article describes the main benefits of PowerShell, such as improved performance and flexibility, and how it can be used to improve security and ensure regulatory compliance. This article is an essential resource for IT professionals who want to learn more about PowerShell and use it to automate and manage Windows systems.
Install PowerShell on the user’s operating system (hereinafter OS). It is installed by default in Windows, there is also an option to install it on Linux and macOS;
Create a file with the format name [filenme].ps1, where ps1 is the PowerShell script format;
Write the code to automate the required task, save the changes in the file;
Run for execution
1. Create a folder called powershell.
mkdir powershell
2. Move to the created folder.
cd powershell
3. Create an empty file of the appropriate type.
type nul > script.ps1
the date
user name
information about the processor
2. To write the code, open the file in a text editor, for example Sublime Text 4 and add a comment that will describe the functionality of this script and add a comment using # [comment text]
# This script gets the username, CPU information and prints the data
3.After writing the comment, we will add the following tapes to this script:
display the current date; Get-Date.
As you can see, we received a message that this user is unable to call scripts to execute, so let’s figure out how to fix this. For the security of the Windows OS, Microsoft engineers decided to create certain policies that would limit users in certain actions. That is why, by default, in most versions of OC Windows, an ordinary user does not have access to run scripts. The parameter responsible for this access is called ExecutionPolicy.
Get-ExecutionPolicy -List
2. The figure shows Scope (hereinafter scope), which is responsible for a certain sphere of influence of the ExecutionPolicy parameter:
- Set by group policy for all computer users;
- Set by group policy for the current computer user;
- Only affects the current PowerShell session;
- Affects current user only;
- A default scope that affects all users of the computer.
3. To view the ExecutionPolicy parameter only for the CurrentUser scope, you can use the following command:
Get-ExecutionPolicy -Scope CurrentUser
4. To set the value of a certain policy, the Set-ExecutionPolicy command is used, let’s apply it:
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
2. To view the ExecutionPolicy parameter only for the CurrentUser scope, you can use the following command: NishangNishang