Today, we wrap up our final deep dive into Powershell. For the past three weeks, we have been exploring the benefits of inline .NET code in your PowerShell scripts. These posts come from Manning Publications’ new book: PowerShell Deep Dives. Because I know you all are anxious to wrap up this series, here is part 3, .NET class with methods.
Category Archives: PowerShell
This category contains any PowerShell related posts.
PowerShell Special: Inline .NET code Part 2
Last Wednesday, we started our deep dive into PowerShell. This week, we continue our exploration of Inline .NET code when scripting. This trick allows you to extend PowerShell and to create custom commands for your environment. If you are interested in other techniques like this, pick up a copy of PowerShell Deep Dives and start really exploring PowerShell!
Today’s tutorial focuses on creating a .NET class. This section was written by Richard Siddaway:
PowerShell Special: Inline .NET code Part 1
For the next three Wednesdays, we will be teaming up with Manning Publishing to take a deep dive into PowerShell. These lessons are advanced. Because I do not come from a scripting background, I found them very useful! If you don’t come from a scripting background and want to learn more about PowerShell, take a look at these two books that explain PowerShell in English! Pretty much any script you see on this site uses techniques and logic from both of those books.
In this series, we will be covering the extremely helpful technique of extending PowerShell through the use of .NET code. These excerpts come from the new book, PowerShell Deep Dives by Jeffery Hicks, Richard Siddaway, Oisín Grehan, and Aleksandar Nikolić. Stay with me through this series – while you won’t get a case of the bends, you will learn some great new PowerShell tricks!
This section was written by Richard Siddaway:
PowerShell is .NET-based. This enables you to use the .NET framework in your PowerShell scripts by loading the relevant assemblies into PowerShell (if they aren’t part of the default assembly set) and then using them via New-Object. You can create intricate GUI applications as a front end to your scripts, for instance. You can also use .NET code directly in your scripts.
Enabled Inactive Computers or Why I fear the Zombie Compocalypse!
Active Directory Administrator should regularly clean up stale computers from Active Directory. This is a fact. If you haven’t automated the stale computer cleanup process, take 10 minutes to read this background article and to set it up. Doing so will make your life easier. After all, cleaning up your stale computers will help you by:
- Reducing complexity (and troubleshooting time) as you don’t have computer sharing near identical names
- Provide an accurate count if you are using an Active Directory based inventory.
- Allow you to assign specific users to a single primary machine for remote management.
When a computer is marked as stale, it can occasionally come back to life! I like to call these zombie computers. It makes my day sound more exciting…
How do these stale computers come back to life? Here is an example: a user might have a laptop off the domain for a year. This laptop would be marked as stale and disabled. When the user returns, a help desk technician might re-enable the laptop without moving it from your Stale Computers container.
Just this week, we had 9 computers that had this issue. That meant 9 computers were not being managed by Group Policy! That meant 9 computers that did not have AppLocker, UAC, or other security settings applied to them! That mean 9 computers with a craving for human brains! Fortunately for us, PowerShell can fix two out of these three problems automatically! A shotgun will fix the last one…
A PowerShell Script to Change Computer Names
Have you ever had to rename a lab of computer or even an entire site? I have been checking computer names in Active Directory this week. Besides cleaning up stale computer accounts, I have been trying to ensure that all of my computer names are standardized. Today, I noticed that a lab of 36 computers was missing one computer.
When this lab was replaced in the summer, someone accidentally named a computer incorrectly. When I physically checked the lab, the computer at spot 12 was named 13. This caused every computer to be off by a name. Not wanting to login to 20+ computers and rename them manually, I turned to my trusty friend – PowerShell. Let’s see if the Rename-Computer cmdlet can give us a PowerShell script to change computer names!






