Last time we saw how to get our Internet Explorer settings out of the registry. And in PowerShell, for nearly every 'Get', there's an equivalent usage for 'Set'.
Here's how it works. Suppose we wanted to change, say, the Start Page for Internet Explorer. First, let's get the current setting (We'll use variables to minimize typing):
$path = 'HKCU:\Software\Microsoft\Internet Explorer\Main\'
$name = 'start page'
(Get-ItemProperty -Path $path -Name $name).$name
As we can see, the IE start page is currently set to msn.com
So where there's a get, there's a set:
$value = 'https://www.google.com/'
Set-ItemProperty -Path $path -Name $name -Value $value
Now we've set IE's start page to google.com. We can test this by running the Get-ItemProperty command again to get the setting, or simply launch IE and see what comes up.
PowerShell can quickly display information from the Registry, provided we know the key's path. For example, here's how to find our Internet Explorer settings:
Get-Item 'HKCU:\Software\Microsoft\Internet Explorer\Main'
Of course, "HKCU" is short for "HKEY Current User". 'HKLM' would be short for "HKEY Local Machine", etc.
PowerShell can quickly search text files for a string of characters:
Select-String -Path .\servers.txt -Pattern "abc"
For this example, we used Select-String to search a list of server names in a text file called 'servers.txt', then used the -Pattern parameter to designate the string we're looking for.
PowerShell returned the filename, the line number where the pattern was found, and the full line.
Note: case is not sensitive here. A search for "ABC" will return the same result.
PowerShell can easily create zip archives of files and folders using the Write-Zip cmdlet.
Get-ChildItem C:\MyScripts\*.ps1 | Write-Zip -OutputPath C:\Temp\PS-scripts.zip
Here we zipped up all the PowerShell scripts written or downloaded for archive purposes:
Get-ChildItem also has a -Recurse parameter if we want to zip up subfolders, and the Write-Zip cmdlet has a -IncludeEmptyDirectories parameter if we want to, well, include empty directories.
Long, long ago, computers mastered the art of multiplying numbers. A more interesting trick is to multiply string. PowerShell can do this easily:
"winner " * 3
Note the trailing space at the end of the string. Without it, the text would all run together in an unbroken line.