Skip to content

5000+ Great Articles

Best Articles & Essays: Interesting Articles to Read Online

  • Enable Private Browsing in IE 11 and Microsoft Edge

    If you want to surf the web and not record your search or browsing history locally on your computer, then Private Browsing (called InPrivate) in IE

  • Best texas instruments ti-30x iis scientific calculator, 10-digit lcd 2020

    Best texas instruments ti-30x iis scientific calculator, 10-digit lcd 2020. 1 - Aproca Hard Travel Case Bag for Texas Instruments TI-30X IIS 2-Line/

  • Controller Vs Mouse and Keyboard For Gaming: Which Is Better? Gaming
  • What Is Augmented Reality and Could It Replace All Screens? Gadgets
  • How To Change Your Google Chrome Theme Google Software/Tips
  • How to Choose and Change Your Next Graphics Card Gaming
  • 3 ways to Rotate Video on iPhone (2018) How-To
  • Unable to Delete Network Adapter in Windows 10? Computer Tips

Using PowerShell for Home Users – A Beginner’s Guide

Posted on October 8, 2020 By blog_786 No Comments on Using PowerShell for Home Users – A Beginner’s Guide

Who doesn’t want to be a wizard and say a few words for magical things to happen? Well, we can’t show you how to become a wizard, but we can show you how to do a little computer magic.

If you have a Windows computer running Windows 7, you have PowerShell. Also, if you have a Windows 7 PC, update it for security.

Using PowerShell for Home Users – A Beginner’s Guide

But this article isn’t just for Windows users. The latest version of PowerShell is free and can be installed and used on both Mac and Linux computers.

This is important because what you’ve learned about PowerShell can now be used on almost any computer. Who knows? You can take this skill to the next level and pursue a career in information technology.

What is PowerShell?

Microsoft’s hi-tech answer is that it is ” a command line shell designed specifically for system administrators.” Sounds intimidating. But this is not the case Do you care about your computer? Yes, then you are the system administrator in your home.

Are you telling your computer what to do with clicks and keystrokes? Yes, so think of the command line shell as just another window where you enter information to tell the computer what to do. Can you do it.

– /

PowerShell is similar to a programming language, but not as cryptic as most others. It is indeed very similar to regular English, which Microsoft has been aiming for for non-programmers to master.

It’s a way to write multiple lines of commands called a script to make the Windows operating system do what you want it to do. Then you can save these lines to a file and run it with one click, or schedule it to run periodically.

What can you do with PowerShell?

The key to PowerShell is the ability to automate tasks so that you don’t have to waste time on your day to day activities. For a professional sysadmin, this can be something like creating new users, generating passwords for them, and sending an email with details to their new boss.

Manually, using clicks and typing, this process can take from 5 minutes to an hour or more. With the right scripts in place, the sysadmin might not even have to do any part of this.

But you want to know what you can do with PowerShell at home. Pretty much anything you don’t like doing over and over. Use it to free up hard drive space by deleting temporary files and log files that you don’t need.

Set a curfew on your child’s computer. Rename or organize a bunch of files. That’s the beauty of PowerShell. Pretty much anything you can do on your computer you can create with a PowerShell script to automate and run with one click or on a schedule.

How do I use PowerShell?

The easiest way to work with PowerShell is with the PowerShell Integrated Scripting Environment (ISE). You can find it by clicking Start and typing powershell ise in the Windows 10 search bar. You should see it as shown below.

Using PowerShell for Home Users – A Beginner’s Guide

The first time we use it, we will run it as administrator. To do this, you must first have administrator rights on your computer. From the Start menu, right-click PowerShell ISE, then select Run as administrator.

Using PowerShell for Home Users – A Beginner’s Guide

You may receive a User Access Control (UAC) warning popup asking if you really want to do this. Click Yes.

Using PowerShell for Home Users – A Beginner’s Guide

You are now looking at the PowerShell IDE. The top pane of the window (1) is the script pane. This is where you write your script. The bottom pane of the window (2) is the console area. When you test your script, you will see the result in this panel.

You will also see error messages here to help you fix and improve your scripts. The panel on the right side of the window (3) is a command add-on. Think of it as a dictionary of all the PowerShell commands available to you.

Using PowerShell for Home Users – A Beginner’s Guide

PowerShell is configured to not run any scripts other than those that are already part of Windows. You will need to change it so you can run your own scripts.

In the script window, copy and paste the following:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

The Set-ExecutionPolicy part of it is called a cmdlet (pronounced cmdlet). Cmdlets are powerful. Think of them as short commands that you can give Windows, and Windows will do a bunch of more complicated things to satisfy your command.

An analogy would be: advise your child to clean the room. Briefly and to the point. If your child is good at cleaning a room, they’ll go out and make the bed, put the laundry in the basket, put their toys and books on the shelves, and maybe even vacuum the floor. They understand what the Clean-YourRoom cmdlet means.

At the top of the window, you will see a green arrow. Click on it to run the command.

Using PowerShell for Home Users – A Beginner’s Guide

The -ExecutionPolicy part tells Set-ExecutionPolicy which policy to set. This is a parameter. He says, “I want you to work according to these principles and do just that. He tells him to use a specific RemoteSigned policy.

The RemoteSigned policy states that PowerShell cannot execute or run any script downloaded from the Internet unless signed by a trusted publisher.

In a roundabout way, it tells PowerShell that you can run any script you create locally because it doesn’t need to be signed by a remote trusted publisher. Now your PowerShell script can run whatever script you write on your computer.

Let’s take a look at a script for deleting temporary files. It’s not as powerful and thorough as CCleaner, but CCleaner has its own set of problems.

Use PowerShell to create hard drive space

We’ll walk through this scenario line by line so you can see how it works. The script will be shown in full at the end, so you can copy and paste it if you like.

$ TempFileLocation = “C: Users username Appdata Local Temp *”

Anything before the dollar sign is a variable name. Think of it like a wallet to put your valuables in. The wallet reminds us of the dollar sign, valuables sound like variables, so we’ll remember that too. We create a wallet or variable named $ TempFileLocation. The equal sign tells PowerShell what to insert into this variable.

In this case, we specify the location of the Windows temporary files – C: Users username AppData Local Temp *. We do this for two reasons; it’s where it’s always safe to delete files from, and we’re going to use it to tell PowerShell where it should go to delete files.

Where your username appears in that space, replace it with your username. This is the username that you use to log into your computer. The asterisk (*) at the end is a wildcard character. It represents everything in the Temp folder because everything in the Temp folder is temporary and we want to delete it.

Double quotes around the location are also important. This tells PowerShell what the string is inside. Think of a string as a string of letters and symbols. If these were regular numbers, we wouldn’t be using quotes.

$ TempFile = Get-ChildItem $ TempFileLocation -Recurse

We are making another variable. This time we’re going to use the command to come up with something to put in the $ TempFile variable.

Get-ChildItem

Another thing you’ll notice about cmdlets like Get-ChildItem is that they are completely readable. See how the first word is a verb? All cmdlets start with action words, so you know immediately what they are doing. ChildItem is two nouns.

The second part of the cmdlet always tells us which PowerShell action will take. ChildItem means all children of the parent location. It’s like saying, “Get all the files that are in a folder, with the files being children and the folder being the parent.

Which cmdlet gets the children? Everything in the $ TempFileLocation variable. PowerShell will jump to the location we put in $ TempFileLocation earlier and get all the children that are there. Then it will put them in the $ TempFile variable.

So what about the -Recurse part? This tells Get-ChildItem to go through everything in that location. Don’t immediately upload files to the parent folder. If there are folders in that folder, get all their children, their children, and so on. We’re going to get them all.

$ TempFileCount = ($ TempFile) .count

Yes, we are creating a third variable called $ TempFileCount, and we are going to put a number in this variable. Where is the number? Well ($ TempFile) .count will give us that number. You probably guessed that the .count part will count all the files we just saved in $ TempFile.

Why did we do it? Mainly because it’s nice to know how many junk files we clean up with the rest of the script to determine how efficient it is.

if ($ TempFileCount -eq 0)

We are now setting up the conditional expression. You can see that he is asking if. If anything? If the brackets are true or false. The parentheses are important, otherwise If doesn’t know what to compare. Here he asks if the number we stored in $ TempFileCount is zero.

-Eq is short for equality. This is a variation on the comparison operator. It’s like telling your kids, “If your room is clean, great, we’re going to do something ” This statement says that if the number stored in $ TempFileCount is zero, do the following.

{Write-Host “There are no files in the $ TempFileLocation folder” -ForegroundColor Green}

This will happen if $ TempFileCount is zero. The curly braces are important. They tell PowerShell to only do what’s inside them if $ TempFileCount is zero.

It will write to the host or screen: “There are no files in the C: Users username Appdata Local Temp * folder.” The -ForegroundColor parameter at the end tells PowerShell to turn the text green. It just makes it easier to distinguish from the error message, which is usually red.

Otherwise

You know what else it means. This is the “Better clean your room or else…” part to see if your child has cleaned his room. This is what happens if $ TempFileCount is nonzero.

{$ TempFile | Remove-Item -WhatIf -Confirm: $ false -Recurse -Force -WarningAction SilentlyContinue -ErrorAction SilentlyContinue}

This indicates a jump to the current location stored in $ TempFile. The vertical line after it is called the pipe. It works like a real pipe because it tells PowerShell to pipe the contents of $ TempFile to the cmdlet as if the water were piping into the washing machine. The Remove-Item cmdlet then does what it says; it removes everything in that location.

The -WhatIf parameter is very important at this stage. It tells PowerShell to run the command, but just try it, don’t delete anything. Just show us what it would be like if we really did.

This allows you to test commands without changing anything on your computer. Leave -WhatIf there until you are sure the script will do what you want and nothing else. Then just remove that and the script will do its job.

Using PowerShell for Home Users – A Beginner’s Guide

The -Confirm: $ false parameter prevents the script from asking if you really want to delete the file. You know what -Recurse does. -Power means to remove that thing no matter what. -WarningAction is SilentlyContinue.

Thanks to this, the script will not warn you about what you are deleting. -ErrorAction is SilentlyContinue, so if there is any error in the process, it just keeps running.

Now we are on the last line.

Write-Host “Cleaned up the $ TempFileCount files in the $ TempFileLocation folder” -ForegroundColor Green}

Just like the first time, Write-Host will output the following sentence so that we know what happened. It will tell us how many files have been removed from the folder it just processed, and it will highlight it in green so that they are easy to spot.

Let’s look at the whole scenario:

$ TempFileLocation = “C: Users guymcd Appdata Local Temp *”
$ TempFile = Get-ChildItem $ TempFileLocation -Recurse
$ TempFileCount = ($ TempFile) .count

if ($ TempFileCount -eq “0”) {
Write-Host “There are no files in the $ TempFileLocation folder” – ForegroundColor Green
}
Otherwise {
$ TempFile | Remove-Item -Confirm: $ false -Recurse -Force -WarningAction SilentlyContinue -ErrorAction SilentlyContinue
Write-Host “Cleaned up $ TempFileCount files in $ TempFileLocation folder” -ForegroundColor Green
}

You can copy and paste it into your PowerShell ISE and save it as something like delete-TemporaryFiles.ps1. Now you can stick to the naming convention for cmdlets when you understand them.

If the code doesn’t work for you for some reason, you can also download the PowerShell script we created and just run it. Just unzip it to view the script file.

Whenever you want to run this script, just right-click it and choose Run with PowerShell. The PowerShell console will pop up for a second or two while your script does its job, then disappear if there are no errors.

Using PowerShell for Home Users – A Beginner’s Guide

Where can I learn more from PowerShell?

It seems like a lot! For your first PowerShell script, this is not bad. If you’ve come this far, applaud yourself. You have learned a lot today, but now you want to know more. Wonderful!

There are many resources on the Internet for more information on PowerShell. A good place to start is in our article “Creating a List of Programs to Run Using the Command Prompt or PowerShell”. Then check out other resources:

  • Getting Started with Microsoft PowerShell – Microsoft Virtual Academy
  • PowerShell Tutorial – TutorialsPoint.com

– –

Share this:

  • Twitter
  • Facebook
Tools Review

Post navigation

Previous Post: SD Card Can’t Be Read? Here’s How to Fix It
Next Post: Disable Adobe Flash On Your PC & Why You Would Want To

Related Posts

  • How Google’s Experimental Apps Can Help You Fight Digital Addiction Tools Review
  • 3 Free Tools to Benchmark a Windows Gaming PC Tools Review
  • How To Block Sites With Free Parental Control Software Tools Review
  • Differences Between the Many Archive Compressed File Formats Tools Review
  • Gravel calculator Calculator
  • HDG Explains : What is SQL, T-SQL, MSSQL, PL/SQL, and MySQL? Tools Review

Leave a Reply Cancel reply

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

Archives

  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • March 2021
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • December 2019
  • July 2019
  • May 2019
  • April 2019
  • January 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018

Categories

  • AI Tools & Guides
  • Amazon Web Services
  • Apple Watch
  • Computer Tips
  • Cool Websites
  • Featured Posts
  • Free Software Downloads
  • Gadgets
  • Gaming
  • General Software
  • Google Software/Tips
  • Hardware
  • Help Desk
  • How-To
  • iOS
  • iPad
  • iPhone
  • islamic Books
  • Linux
  • Linux Tips
  • Mac OS X
  • macOS
  • MS Office Tips
  • Networking
  • Office Tips
  • OS X
  • Product Reviews
  • Reviews
  • Safari
  • Smart Home
  • Smartphones
  • Software Reviews
  • technology
  • text
  • Tools Review
  • Troubleshooting
  • Tutorials
  • Uncategorized
  • Urdu Books PDF
  • Web Site Tips
  • Windows
  • Windows 10
  • Windows 7
  • Windows XP Tips
  • Wordpress
  • Six Copyscape Alternatives That you can use
  • How to Make Phone Calls Without Revealing Your True identity
  • 50 Useful Websites on the Internet You Didn’t Know Existed
  • Everything You Need to Know About WannaCry Ransomware Attack
  • Automatically Transcribe YouTube Video/Audio with Google Docs
DMCA.com Protection Status

Recent Posts

  • 8 Best Free and Paid Cloud Storage (2017)
  • Six Copyscape Alternatives That you can use
  • 4 Different Ways to Test your Internet Speed
  • How to Make Phone Calls Without Revealing Your True identity
  • Use Secret Silver Subscription Plan to Save Money on Audible

Recent Comments

  1. 6 Things You Need Know About Email Encryption on Delete All Emails from Gmail With Once Click
  2. Looking For YouTube Alternative? Try These 7 Video Sharing Sites on Ten Best YouTube Video Editing Software 2023
  3. 8 (+1 New) Ways to Post on Instagram From Computer on How I Solved My Bluestacks Graphic Card Error (2 Ways)
  4. Find out what WordPress Theme and Plugin a Website is Using on How to Install a Theme on WordPress
  5. KeepVid Music: Use Online Music as your Personal Music Library on Top Ten Best iPad Music Apps
  • 5 Sites To Find Limited & Special Edition Video Games For Sale

    The world of video games today is very different from what it was a - perhaps primarily the dominance of digital purchases. While one can argue abo

  • How to Get Netflix “Screen Lock” on Prime Videos And YouTube How-To
  • How To Remove Microsoft Edge From Windows 10 Windows 10
  • How to Switch iTunes App Store Account to Another Country Computer Tips
  • 5 Ways to Crack or Reset a Forgotten Windows Password Computer Tips
  • Best ti-30 calculator 2020

    Best ti-30 calculator 2020. 1 - Texas Instruments TI-30X Solar Scientific Calculator w/Quick Reference Card Top Reviews

  • Best ti-nspire calculator 2020

    Best ti-nspire calculator 2020. 1 - Texas Instruments TI-NSpire Math and Science Handheld Graphing Calculator Top Reviews

  • 13 Typing Games for Kids to Learn How To Type Faster

    In today's digital world, it is very important for children to be able to type. Even in elementary school, technology is the norm, and most kids hav

Copyright © 2023 How To Blog.

Powered by PressBook News WordPress theme

Go to mobile version