Hey all,
Recently was messing around with Windows Powershell and making a few little scripts. I'm going to be learning more as I go, but figured this would be a nice little blog segment entitled PowerShell Pickups. PowerShell Pickups will be little snippets of code, scripts, and information while I learn more things in PowerShell.
For these I just used Windows PowerShell ISE which is a little IDE type environment for PowerShell. You can also use notepad as well and save the file as .ps1
Note: To get these scripts to run you may have to change a policy on your computer. For me, I did Set-ExecutionPolicy RemoteSigned
and then I was able to run my PowerShell commands. If you want to undo this you would use
Set-ExecutionPolicy Restricted
My first little script does the job of killing all browser processes for every browser on a system. I often have a bunch of windows open with multiple tabs. Overnight, things tend to break or Flash will crash leading to a massive hangup. It can be hard to get the windows to close manually, so I'll be keeping this little script handy on my desktop. The script is below:
Stop Browsers.ps1
Stop-Process -processname chrome
Stop-Process -processname firefox
Stop-Process -processname iexplore
Stop-Process -processname opera
Stop-Process -processname safari
Running this script will cause all of the above programs to close if they're open. If they are not open, an exception will be thrown saying that it could not be found.
Note: You could close out other programs this way too. Open task manger and look at the process list to get the process name and switch programs in and out as necessary.
If you play with PowerShell or want to start learning it, give the above a try. A quick little way to see some commands and results.
No comments:
Post a Comment