business, technology, notebook-2717063.jpg

PowerShell’s Most Useful Set Commands

Set Commands

PowerShell is a powerful tool that can be used to automate and manage tasks in Windows systems. One of the most useful features in PowerShell is its “Set” command, unlike “Get” commands which is covered in this post , “Set” command which allows users to modify the state of their system. In this blog post, we will discuss three of the most useful set commands in PowerShell.

Set-ExecutionPolicy

The Set-ExecutionPolicy command is used to set the execution policy for PowerShell scripts. By default, PowerShell is configured to prevent the execution of any script. This is a security feature designed to prevent malicious code from being run on your system. However, this can be an inconvenience for users who need to run scripts frequently. The Set-ExecutionPolicy command can be used to change the execution policy to allow scripts to run. For example, to set the execution policy to allow all scripts to run, you can use the following command:

Set-ExecutionPolicy Unrestricted
Shows Execution Policy to enter desired policies

As seen in above image Set-ExecutionPolicy without any parameters will prompt to enter values, like Unrestricted. For example, command would be Set-ExecutionPolicy -ExecutionPolicy Unrestricted

Additional available values are

AllSigned
Bypass
Default
RemoteSigned
Restricted
Undefined


Set-ItemProperty

The Set-ItemProperty command is used to set the value of a property for a specified item. This command is particularly useful for modifying registry keys. For example, to set the value of the “Start” key for a service to “2” (which means the service will start automatically), you can use the following command:

Set-ItemProperty -Path "HKLM:\\SYSTEM\\CurrentControlSet\\Services\\{ServiceName}" -Name "Start" -Value 2

Set-NetIPAddress

The Set-NetIPAddress command is used to modify the configuration of a network interface. This command is particularly useful for changing IP addresses and subnet masks. For example, to change the IP address of a network interface to “192.168.1.100” and the subnet mask to “255.255.255.0”, you can use the following command:

Set-NetIPAddress -InterfaceAlias "Ethernet" -IPAddress "192.168.1.100" -PrefixLength 24

Conclusion

PowerShell’s “set” command is an incredibly useful tool for managing and automating tasks in Windows systems. In this blog post, we discussed three of the most useful “set” commands in PowerShell: Set-ExecutionPolicy, Set-ItemProperty, and Set-NetIPAddress. By mastering these commands, you can become more efficient and effective in your use of PowerShell.

To learn more about Powershell commands, you can visit Microsoft learning portal here.

Read more about Execution Policies here.