Scripting Blog [archived]

Formerly known as the "Hey, Scripting Guy!" blog

Latest posts

Jun 30, 2016
Post comments count 0
Post likes count 0

Find ready-to-use sample PowerShell scripts in the GUI

Doctor Scripto

Summary: Honorary Scripting Guy, Sean Kearney, goes over some often missed, easy-to-use PowerShell techniques for those who are starting out. I had heard a rumor that many of the management tools actually run PowerShell code in the backend. Is there any way to see what code it’s running? Honorary Scripting Guy, Sean Kearney, is here today, and, yes, it’s true. This hidden gem is one of the most frequently missed pieces by many people who use PowerShell. The GUI in many cases is calling up PowerShell. Let’s begin with something pretty simple: managing users in Active Directory and auditing groups. For me, tha...

Jun 29, 2016
Post comments count 0
Post likes count 0

PowerTip: List all available CIM classes by using PowerShell

Doctor Scripto

Summary: Use the Get-CimClass cmdlet to see all classes that you can query from. How can I find a list of Common Information Model (CIM) classes in Windows so that I can ask my computer useful questions? Just run the Get-CIMClass cmdlet to get a list of all available classes in the default namespace in Windows. If you’d like to filter on the list, you can use a wildcard. In the following example, we show all classes that begin with Win32 and have the word, Disk, in it. Get-CimClass Win32*Disk*

Jun 29, 2016
Post comments count 0
Post likes count 0

Use Windows PowerShell as an administrative console

Doctor Scripto

Summary: Honorary Scripting Guy, Sean Kearney, shares his early use of PowerShell as a network administrator. I have a simple but irritating task each day around lunch time. A handful of people usually lock themselves out of Active Directory. Can you help me find an easy way to deal with this? Honorary Scripting Guy, Sean Kearney, is here to help you share the pain. I, too, once felt that prickly feeling on the back of my neck near the end of lunch hour. “Lock out Hell”, I called it. I know that everyone has experienced that, especially on Friday. A handful of people come in and for whatever reason have lock...

Jun 28, 2016
Post comments count 0
Post likes count 0

PowerTip: List all subfolders under a target path with PowerShell

Doctor Scripto

Summary: Use Get-Childitem to provide a printable list of all folders under a path. I used to use tree.com to get a list of folders on a computer. Is there something close to that in PowerShell? Maybe something I could print? If you were to use Get-Childitem combined with Select-Object, you could get a pretty clean list. Here’s an example that targets drive c: and all hidden folders. It displays only directories and their full paths.

Jun 28, 2016
Post comments count 0
Post likes count 0

Erase files based on date by using PowerShell

Doctor Scripto

Summary: Honorary Scripting Guy, Sean Kearney, relates his first experience with PowerShell. I was curious just how difficult it is to use Windows PowerShell. For example, how difficult is it to erase files based on the current date? Honorary Scripting Guy, Sean Kearney, is here today, and I can completely relate to exactly what you’ve said. I once had absolutely zero time to learn about scripting or automation. I was a field technician. You know the typical work for some field techs. You get in the car, go to the call, hop back in the car, off to the next call, lunch in a drive-thru, sleep in a parking lot....

Jun 27, 2016
Post comments count 0
Post likes count 0

PowerTip: Use a destructive PowerShell cmdlet safely

Doctor Scripto

Summary: Use the –whatif parameter with PowerShell cmdlets to test code live. I heard that PowerShell has a built-in safety switch to many of its cmdlets. Could you show me an example of it in use? No problem. You’re referring to the –whatif parameter, which is meant to show you what would happen if you used a PowerShell cmdlet without actually executing the cmdlet. An example of this in action is in the following Remove-Item cmdlet. This will attempt to remove the document, HSG-Article-Sean-Should-Not-Lose.docx, without actually removing it.

Jun 27, 2016
Post comments count 2
Post likes count 5

Use Windows PowerShell to search for files

Doctor Scripto

Summary: Use Get-Childitem to search the files system with PowerShell. I saved a file somewhere on my computer and can’t find it. Is there a way to use Windows PowerShell to find it? Honorary Scripting Guy, Sean Kearney, is here today to show you a cool trick I use all the time. I use PowerShell to search for things constantly! Why PowerShell? Well, to be honest, I have a bad, bad, bad habit of putting data where it shouldn’t be. Sometimes I’d use locations that the Indexer in Windows isn’t watching. In these situations, even Cortana can’t help me. We can use Get-Childitem to show a list of files and/or dir...

Jun 24, 2016
Post comments count 0
Post likes count 0

PowerTip: Remove trailing space from a string by using PowerShell

Doctor Scripto

Summary: Use the trim() method to remove leading and trailing spaces from a string. Could you do me a huge favor and show me how to get rid of spaces before and after a string in PowerShell? No problem at all. All you need to do is apply the trim() method to remove all the output. You can also use trimstart() to remove the start or trimend() to remove the end. Here is an example: $Data=’           Look at all of this wasted space on my screen. $Data $Data.trim() $Data.trimstart() $Data.trimend()

Jun 24, 2016
Post comments count 0
Post likes count 0

Build a hexadecimal clock in PowerShell – Part 5

Doctor Scripto

Summary: Learn to split data in a Here-String and get a console beep. Honorary Scripting Guy, Sean Kearney, is here with our final day this week to wrap up building a hexadecimal clock in PowerShell. When we finished yesterday, we ran across a snag in our output. Most of our rows kept dropping to the immediate left of the screen as in the following image: For this, we will look at one of our Here-Strings to try and figure out the problem: If we look at a Here-String, you’ll notice it is literally a long string. It has an array count of 1 but a large length. The question is, how can I access the i...