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.
Tuesday, July 31, 2018
Wednesday, July 25, 2018
Use PowerShell to Quickly Find Browser Settings
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.
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.
Monday, July 23, 2018
Use PowerShell to Get the Length of an Integer
PowerShell can return the length of a string easily. Wrap the string in parentheses and the the Length property of the object using dot notation:
("Some strings are rather lengthy").Length
But what about integers?
That's because the Length property is counting the integer as a whole rather than looking at the individual units. If we're going to say, "Hey PowerShell, use this string method to get the length of what's in between the parens", then PowerShell is going to assume it's a string, not an integer.
To get around this, we can just convert the integer to a string using the 'ToString()' method:
(6548138735138).ToString().Length
("Some strings are rather lengthy").Length
But what about integers?
That's because the Length property is counting the integer as a whole rather than looking at the individual units. If we're going to say, "Hey PowerShell, use this string method to get the length of what's in between the parens", then PowerShell is going to assume it's a string, not an integer.
To get around this, we can just convert the integer to a string using the 'ToString()' method:
(6548138735138).ToString().Length
Sunday, July 22, 2018
Use PowerShell to launch Internet Explorer
Want to save some time? With PowerShell, we can use Start-Process to launch Internet Explorer:
Start-Process iexplore www.google.com
We can speed that up with an alias, substituting 's' for Start-Process:
New-Alias -Name s -Value Start-Process
We can test the alias with notepad:
s notepad
And a blank notepad should open right up.
Now we should be able to launch Internet Explorer more quickly using our alias:
s iexplore https://en.wikipedia.org
Even better, we can create an alias for Internet Explorer itself. Let's call it 'ie':
New-Alias -Name ie -Value "C:\Program Files\Internet Explorer\iexplore.exe"
(Your system's path to the executable may vary.)
We can test the alias:
ie
and a new instance of Internet Explorer should launch.
If we put those aliases into our PowerShell profile, they'll always be available.
Note: aliases are a good time-saver for our own interactive sessions with PowerShell, but they are not recommended for use in scripts, since the aliases make it harder for others to know what the scripts are doing.
Start-Process iexplore www.google.com
We can speed that up with an alias, substituting 's' for Start-Process:
New-Alias -Name s -Value Start-Process
We can test the alias with notepad:
s notepad
And a blank notepad should open right up.
Now we should be able to launch Internet Explorer more quickly using our alias:
s iexplore https://en.wikipedia.org
Even better, we can create an alias for Internet Explorer itself. Let's call it 'ie':
New-Alias -Name ie -Value "C:\Program Files\Internet Explorer\iexplore.exe"
(Your system's path to the executable may vary.)
We can test the alias:
ie
and a new instance of Internet Explorer should launch.
If we put those aliases into our PowerShell profile, they'll always be available.
Note: aliases are a good time-saver for our own interactive sessions with PowerShell, but they are not recommended for use in scripts, since the aliases make it harder for others to know what the scripts are doing.
Subscribe to:
Posts (Atom)