![]() ![]() What is the cmdlet getting the child items of? Everything in the variable $TempFileLocation. This is like saying get all the files that are in a folder, with files being the children and the folder being the parent. ChildItem means all the children of a parent location. The second part of the cmdlet is always going to tell us to what PowerShell will apply the action. See how the first word is a verb? Cmdlets all begin with action words, so you immediately know what it’s doing. Get-ChildItemĪnother thing you’ll notice about cmdlets like Get-ChildItem is that it is totally readable. This time we’re going to use a command to come up with something to put in the $TempFile variable. $TempFile = Get-ChildItem $TempFileLocation -Recurse If it were ordinary numbers, we wouldn’t use the Tells PowerShell that what’s in there is a string. The double-quotes around the location is important too. ![]() What it represents is everything in the folder Temp, because everything in the Temp folder is temporary We’re doing this for two reasons it’s a location that is always safe to delete files from, and we’re going to use it to tell PowerShell where it must go to delete files. In this case, we’re putting in the location of a Windows’ temporary files location – C:\Users\username\AppData\Local\Temp\*. The equal sign tells PowerShell what to put in that variable. We’re creating a wallet, or variable, named $TempFileLocation. Wallet reminds us of the dollar sign, valuables sounds like variable, so we’ll remember that too. Think of it like a wallet to put valuable stuff in. $TempFileLocation = "C:\Users\username\Appdata\Local\Temp\*"Īnything with a dollar sign in front of it is a variable name. At the end, the script will be shown completely so you can copyĪnd paste it if you’d like. We’ll break down this script, line by line, so you can see Use PowerShell to Create Space on Your Hard Drive It isn’tĪs powerful or thorough as CCleaner, but CCleaner comes with its own set of Let’s look at a script to delete temporary files. Now, your PowerShell script will be able to run any script you write on your computer. In a roundabout way, it tells PowerShell that it’s fine to run any script created locally, because those don’t need to be signed by a remote trusted publisher. The RemoteSigned policy states that PowerShell may not execute, or run, any script that was downloaded from the Internet unless it was signed by a trusted publisher. It tells it to use the specific policy of RemoteSigned. It’s saying, “I want you to work within these guidelines and do specifically this. The -ExecutionPolicy part is telling Set-ExecutionPolicy what policy to set. You can find it by clicking on Start and typing powershell ise into the search bar in Windows 10. The easiest way to work with PowerShell is in the PowerShell Integrated Scripting Environment (ISE). Almost anything you can do on your computer, you can create a PowerShell script to automate and run with a click or on a schedule. Use it to free up space on your hard drive by deleting temporary and log files you don’t need. Pretty much anything that you don’t like doing again and again. With the right scripts, the Systems Administrator may not even have to do any part of that.īut you want to know what you can do with PowerShell at home. Manually done, with clicks and typing, that process can take 5 minutes to as much as an hour or more. For a professional Systems Administrator, that could be something like creating new users, generating passwords for them, and send an e-mail with the details to their new supervisor. The high-level point of PowerShell is to be able to automate tasks, so you don’t have to waste your time doing mundane things repeatedly. Then, you can save those lines in a file and run it with a click or schedule it to run periodically. It’s a way of writing a few lines of commands, called a script, to make the Windows operating system do something that you want it to do. It really reads a lot like regular English, which was something Microsoft strove for so that it could be picked up by non-programmers. PowerShell is like a programming language, but not as cryptic as most. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |