Pinterest Stumbleupon Whatsapp
Ads by Google

PowerShell can be a very intimidating prospect for a novice user Boost Your Productivity With Windows PowerShell Scripts Boost Your Productivity With Windows PowerShell Scripts What if you could bring the productivity of Linux over to Windows? Most Linux distros come packaged with the powerful Bash shell. PowerShell is an equally powerful terminal for Windows. Read More . In 2016, there’s something arcane and archaic about a text-based interface — but becoming proficient can help you take control of your computer in ways you might never have thought possible.

An expert can use PowerShell to carry out all kinds of tasks pertaining to all areas of your system, but that sort of mastery only comes with an understanding of the basics and plenty of practice. By understanding these fifteen tasks, you can start to understand what PowerShell is, and get an idea of just how far its capabilities reach.

Opening an Elevated PowerShell Prompt

To get started with any of these tasks, you’ll need to open an elevated PowerShell prompt. To do so, type Powershell into the Windows search bar, right-click the appropriate result, and select Run as Administrator.

run as admin

Alternatively, you can just type PowerShell into the search bar and hit CTRL + SHIFT + ENTER to get the same result.

Set the Date and Time

There are plenty of ways to set the date on your computer, but the simplicity of the following PowerShell commands make them good practice for a novice 6 Basic PowerShell Commands to Get More out of Windows 6 Basic PowerShell Commands to Get More out of Windows PowerShell is what you get when you give steroids to the Windows Command Prompt. It grants you control of nearly every aspect of the Windows system. We help you leap up its learning curve. Read More . However, you should be careful while tweaking these parameters on a computer that’s not your own — improperly aligned system clocks can wreak havoc on an Active Directory environment.

Ads by Google

To get started, open up an elevated PowerShell prompt and input the following command:

Set-Date -date "12/25/2016 7:30 AM"

Press enter, and your computer should be under the impression that it’s Christmas Day. You can then either test your learning by using the same command to return your system to the correct time and date, or tell your PC to set its time and date automatically once again via the Settings app.

Adjust the Date and Time

In some cases, you might want to tweak the date and time, rather than change it outright. To complete this task, we’re going to use the same Set-Date cmdlet as before with a slightly different method:

Set-Date (Get-Date).AddDays(2)

Above, you can see that we’re running a command that retrieves the date currently set on the computer, then triggers another process that increases the day of the month to the desired value. We could also use AddHours, AddMinutes or AddSeconds to fine-tune this adjustment, or use a minus sign ahead of the number to go back in time rather than forward.

Verify Files and Folders

PowerShell commands can make it easy to check whether files and folders exist on your computer, without you having to spend time digging around in File Explorer How to Get the Most Out of the Windows 10 File Explorer How to Get the Most Out of the Windows 10 File Explorer Windows File Explorer is one of the most underrated features of Windows 10. Here we demonstrate how to manage and control the Windows 10 File Explorer from the bottom up and reveal features you never... Read More . It’s a simple matter of using the Test-Path cmdlet to verify whether there’s anything present at the end of your specified path. For instance, to find a file called PowerShell.xls in a folder titled Documents, I would use a command something like this (obviously, your path will be different depending on your folder hierarchy):

Test-Path c:\Users\Brad\Documents\PowerShell.xls

However, you don’t have to know the exact file name to run a scan. An asterisk can be used as a wildcard 11 Advanced Slack Search Tips That You Should Be Using Now 11 Advanced Slack Search Tips That You Should Be Using Now Searching through Slack can be a pain if you don't take advantage of these advanced searching tips. Read More , which is useful if you want to search for a particular file type, like this:

Test-Path c:\Users\Brad\Documents\*.xls

Rename Files and Folders

Once you’re comfortable typing out file paths accurately, PowerShell can be used to quickly and efficiently rename files and folders. Just remember to open with the Rename-Item cmdlet, then give the existing path, then your desired name — like so:

Rename-Item c:\Users\Brad\Documents\PowerShellisDifficult.xls PowerShellisEasy.xls

Move Files and Folders

Moving files and folders using PowerShell is easy once you’ve used the Rename-Item cmdlet. Just replace the part of the command where you would specify the new name with its new location:

Move-Item c:\Users\Brad\Documents\PowerShellisEasy.xls c:\Users\Brad\Important Documents

Combine that with the wildcard we used earlier on, and you can quickly move files of a particular type from one folder to another:

Move-Item c:\Users\Brad\Documents\*.xls c:\Users\Brad\Important Documents

Open Programs

The Invoke-Item cmdlet opens up applications or files directly from the PowerShell prompt:

Invoke-Item c:\Windows\System32\notepad.exe

However, as long as the application is in your Windows path,  you can do the same simply by its name into PowerShell as so:

notepad

Open Files with Default Program

This cmdlet can actually be put to better use opening files, but there’s a small caveat to be aware of beforehand. Using Invoke-Item to initialize a file will open it in whatever program is set as the default, so make sure that’s set up to meet your needs beforehand:

Invoke-Item c:\MakeUseOf\Hello.txt

Open Files as a Batch

The Invoke-Item cmdlet really shine when it’s combined with the wildcard asterisk that we used earlier. With this command in your arsenal, you can open up an entire folder’s worth of files in a flash:

Invoke-Item c:\MakeUseOf\*.txt

Read Text Files

The text-based interface of PowerShell is never going to be able to compete with VLC 6 More VLC Media Player Features You Must Try 6 More VLC Media Player Features You Must Try VLC is a media player more powerful than you might realize. Are you using it to its full potential? Here are some pointers. Read More over the amount of file types it can display. However, it’s well-suited to presenting the content of .txt files using the Get-Content command:

Get-Content c:\MakeUseOf\Hello.txt

hello world

However, you might just want to preview the text file rather than display the whole document, especially if it’s particularly large. In this case, we can use the -totalcount parameter:

Get-Content c:\MakeUseOf\Hello.txt -totalcount 5

total count 5

As you can see above, only the first five lines of the document are displayed as a result.

Add to a Text File

You can go one step beyond reading the content of a .txt document by using the Add-Content cmdlet:

Add-Content c:\MakeUseOf\Hello.txt "written by Brad Jones"

However, this will just put the added text at the very end of the document as it stands, which might not be exactly what you’re looking for.

written by brad

Here, you can use a special character to stipulate that you want your addition to be added on a new line:

Add-Content c:\MakeUseOf\Hello.txt "`nwritten by Brad Jones"

written by brad jones amended

You might find a few more special characters important enough to commit them to memory, while you’re working with PowerShell 6 Basic PowerShell Commands to Get More out of Windows 6 Basic PowerShell Commands to Get More out of Windows PowerShell is what you get when you give steroids to the Windows Command Prompt. It grants you control of nearly every aspect of the Windows system. We help you leap up its learning curve. Read More . Using `b will result in a backspace, and `b will produce a horizontal tab. Meanwhile, `’ will produce a single quote and `” will produce a double quote.

Measure a Text File

Whether you’re trying to hunt down a particular file with an anonymous name, or you just want to know how much code you managed to produce 4 Questions to Ask Yourself Before Learning How to Code 4 Questions to Ask Yourself Before Learning How to Code Learning a programming language is popular. But is it for everybody? Before you commit to it, do ask yourself the following questions and be honest. Read More over the course a day of programming, PowerShell offers a very efficient method of measuring the number of lines in a text file. Use the following command:

Get-Content c:\MakeUseOf\Hello.txt | Measure Object

measure content

Now, we’re using two cmdlets in unison — and that’s only going to become more important the deeper you dive into PowerShell 3 Clever PowerShell Functions After Upgrading to Windows 10 3 Clever PowerShell Functions After Upgrading to Windows 10 Windows 10 brings us a new PowerShell, essentially Command Prompt on steroids. This article shows you how to do the otherwise impossible with PowerShell. And it's easier than you think! Read More .

Security and System Admin

If your computer is exhibiting unusual behaviour 8 Annoying Windows 10 Issues & How to Fix Them 8 Annoying Windows 10 Issues & How to Fix Them The upgrade to Windows 10 has been smooth for most, but some users will always encounter issues. Whether it's a flashing screen, network connectivity issues, or battery drain, it's time to resolve these problems. Read More , you might not have access to the channels you would normally use to diagnose the problem. At times like this, knowing how to retrieve the same information using PowerShell can be very handy.

Get-Service is one cmdlet that’s well worth making a note of, as calling it will display all services installed on your computer alongside their current status:

Get-Service

However, we can use a more complex command to stipulate the kind of services we want to see information about:

Get-Service | Where-Object {$_.status -eq "stopped"}

This will only display the services that are currently stopped by checking the status of each individual object (represented in the command by $_). We could replace the word stopped with running to receive the opposite set of services.

Restart a Service

Once you’ve established that a service is causing the problem, we can restart it directly from PowerShell:

Restart-Service dbupdate

We can also use a parameter that allows us to refer to the service by its display name, rather than the potentially confusing name that the system uses:

Restart-Service -displayname "Dropbox Update Service"

Modify a Service

Some service issues might not be fixed by a simple restart. If your problem is being caused by a troublesome service that defaults to opening at startup Remove Windows Startup Items to Fix Your Slow Computer for Free Remove Windows Startup Items to Fix Your Slow Computer for Free Programs launching at boot can affect both the Windows startup speed and your computer's overall performance. Fix your slow computer by removing applications from auto-start. We show you how to catch them all. Read More , you can use PowerShell to change these settings:

Set-Service dbupdate -startuptype "manual"

Depending on what you’re trying to accomplish, you can also use “automatic” and “disabled” in place of the word manual.

Refresh Stuck Apps

If an app is stuck at its splash screen or fails to initialize, it can be incredibly frustrating. The jump to Windows 10 How to Say "No" to Windows 10 on Your PC How to Say "No" to Windows 10 on Your PC Tired of postponing the Windows 10 update? Microsoft has made it easier for you to say No! Read More emphasized apps over traditional programs, and this type of software often doesn’t give the user much opportunity to troubleshoot problems.

However, PowerShell can be used to offer up a workaround for this type of problem — thanks to MakeUseOf reader Gary Beaty for this tip:

Get-AppXPackage -AllUsers | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}

This is the most complex command we’ve worked with so far, so don’t be disheartened if you don’t quite understand all the elements that are in play. However, based on what you’ve learned about concepts like cmdlets, parameters, and some of the techniques used elsewhere in this article,  you should be able to make an attempt at unpacking at least some of what’s going on above.

Next Steps

These fifteen techniques are just an introduction to what PowerShell is capable of Command Prompt vs. Windows PowerShell: What's the Difference? Command Prompt vs. Windows PowerShell: What's the Difference? Windows users can get by without using either the Command Prompt or PowerShell. But with Windows 10 and new features around the corner, maybe it's about time we learned. Read More . Digging further into its capabilities will require a little bit of coding knowledge, or at least a willingness to learn — but putting the time in will reap rewards.

Microsoft’s Windows PowerShell Owner’s Manual is a good place to start. From there, it’s worth checking out the PowerShell subreddit. Be warned that the vast majority of users on the board are experts, so you may feel out of your depth at first. However, it’s a great place to go to see what experienced users are capable of and get inspired to improve your skills.

Are you looking for help with PowerShell? Or ready and willing to share your insight? Why not join the conversation in the comments section below?

  1. t333to
    October 23, 2016 at 10:04 pm

    Whats really useful is chocolatey (works with cmd too), write something about choco...

    Its sort of a windows package/program manager. Once set you can install programs with simple commands, e.g. VLC, you type into cmd/PS: "choco install vlc" and the rest is magic.

  2. bob
    October 23, 2016 at 2:28 pm

    Too bad 99% of this can be accomplished just with an elevated cmd prompt.

  3. Ray
    October 2, 2016 at 6:13 pm

    Wow! Such advanced, much powerful! Setting the date and time... Holly ?hit! Awesome!

  4. BMOREiTGUY
    September 3, 2016 at 10:58 pm

    Whoa! Way to advanced!! I usually think of advanced as something you can do with CMD prompt...

  5. Christian
    September 2, 2016 at 5:02 pm

    "Using `b will result in a backspace, and `b will produce a horizontal tab"? I think you meant `t there.

  6. Sourabh
    June 10, 2016 at 5:51 pm

    "Advanced" .. Yeah sure.

Leave a Reply

Your email address will not be published. Required fields are marked *