Rebuilding your PC is always a drag, even with useful utilities like Ninite.
I recently created a PowerShell DSC script that I can use whenever I need to rebuild my PC. As part of that, I used the cChoco provider to automatically install applications using Chocolatey. I’ll be writing a blog post with more details shortly.
That’s a great way to get the applications installed, but not for keeping them up-to-date. Chocolatey allows you to run ‘choco upgrade all’ manually to do this:
Rather than manually create the scheduled task to automate this, I created this short PowerShell script:
The script will:
- Locate the choco.exe binary (It’ll quit if it can’t find it in the path)
- Set up a scheduled task that runs said binary at system startup
Note that this script will only work on Windows 8 and newer machines, because it relies on the *-ScheduledTask cmdlets.
Yesterday I was working with two IT professionals who had probably over 25 years of combined experience working with Windows, but neither of them was aware of this useful technique.
If you have a variable that you’d like to grab the value of and put it into the clipboard, the easiest way to do this is to pipe it to the built-in clip.exe
$env:Path | clip
The above will result in the contents of the ‘path’ environment variable being put into the clipboard.
If, like any sane sysadmin, you adhere to best practice and your own user account isn’t a domain admin, you’re likely to be running certain operations as a domain admin.
I’ve used batch files to run CMD, MMC, and other applications as a domain admin account in the past. To run PowerShell, I had to use a slightly different method.
1. Create a PowerShell script that contains the following, and save it somewhere:
Start-Process powershell.exe -Credential "domainadministrator"
2. Create a shortcut on your desktop or similar, with the following path:
%SystemRoot%system32WindowsPowerShellv1.0powershell.exe -File C:pathtoscriptRun-PowerShell-Elevated.ps1
3. Optionally, set the shortcut icon to one of the ones contained in the PowerShell exe. I used the UAC one.
To test that it worked, run the script, authenticate, and then do the following:
You should see that the username matches the one you started the process as.
If you need to extract a file into a particular folder, what do you normally do? Some people may copy the Zip file into the destination folder, and then unzip it. Others may launch their unzip tool of choice’s file manager and use the unzip wizard to point to the destination folder.
7-Zip provides a handy way to do this. All you need to do is right-mouse-drag the Zip file to the destination folder, release the right-mouse button, and go to 7-Zip –> Extract … from within the context menu.
I’d been using 7-Zip for years before I figured this one out.