The FREE 2017 #PSBlogWeek eBook is Here!

2017’s #PSBlogWeek is long over and as a tradition, I’ve created an eBook commemorating this great event. Thanks to all of the bloggers that wrote some awesome posts and I hope we can do this again soon! As promised, the 2017 #PSBlogWeek eBook is completed and now available. Feel free to put it up on your blog, tweet about it, share it on Facebook or anywhere where you think people will enjoy it. All I ask if you link back to the original blog post announcing it here.

Read more

Using Car Time as Learning Time

I have an eight-year-old daughter whom I drive to school every day. I didn’t use to, but I do now because not only does it give me a chance to get out and about—I work from home all the time and I rarely leave the house; once a week or once every two weeks—but, for the most part, it allows me to step back and think about things more. My daughter is a major introvert like me if you could believe that. She just likes to sit back there in the very back seat with her iPad and her headphones on. I like to take her to school to get the time to listen to podcasts. If you’re not listening to a podcast, any kind of educational podcast, then you are doing yourself a disservice. I enjoy using the podcatcher app DownCast but there are lots of others out there. […]

Read more

Get-WmiObject: Querying WMI on Local and Remote Computers

Whenever we need to discover just about any information about a Windows computer and it’s components, we can do so with Get-WmiObject. Not only reading, by leveraging WMI methods, Get-WmiObject can also run actions on local or remote systems as well. This cmdlet is one of a couple in PowerShell that can work with the WMI repository to make managing lots of systems a whole lot easier. Discovering Classes with Get-WmiObject At it’s most basic this cmdlet can query information from a local computer. All you’ll need to know is the namespace (probably root\cimv2 which is default) and the WMI class where the information you’re looking for is located. There are thousands of classes, and you probably don’t know which class you’d like to use yet. Using Get-WmiObject, we can query all of the available classes in a namespace. Using Get-WmiObject -List, you’ll be able to see all of the […]

Read more

Out-File: Using PowerShell to Redirect Output to File

Similar to a previous cmdlet of a day we covered, [Set-Content](https://www.adamtheautomator.com/powershell-write-file-set-content/), PowerShell also has another cmdlet called Out-File that performs a similar feat which is write output directly to a text file. Unlike the general Set-Content cmdlet that’s purpose is a universal cmdlet to create or overwrite a file at any point in a script, the Out-File PowerShell cmdlet was designed to replace the standard output redirection operator (>). Even from the DOS days, we could redirect output to a file. This cmdlet is the PowerShell way to do it. Basic Out-File Usage This cmdlet is simple to use as was the standard output redirection operator before it. Its sole purpose is to send the raw output directly to a text file with no regard. There are minimal ways to tweak how that output is written. To demonstrate, I can retrieve all of the services from a local machine which […]

Read more

Test-Connection: Ping Remote Hosts the PowerShell Way

Today’s cmdlet of the day is Test-Connection. Test-Connection is a cmdlet that not surprisingly tests your network connection. Think of Test-Connection as PowerShell’s implementation of the popular ping utility. Even though both have ICMP in common, you’ll see that the two methods are a little different under the covers. Using this cmdlet is simple. At it’s most basic, just specify a ComputerName parameter, and it will send four ICMP requests to the destination host.

This output looks similar to ping.exe and, on the surface, it is but Test-Connection issues the ICMP request a little differently. Unlike ping.exe, Test-Connection is using the local computer’s WMI class Win32_PingStatus to send the ICMP request. Using the local WMI repository means you’d better be sure your local WMI repository is healthy else Test-Connection will not work. Test-Connection’s Object Output Also, as with the beauty of PowerShell, this cmdlet doesn’t merely return what immediately […]

Read more

Get-AdComputer: Find Computers in OUs with PowerShell

For today’s cmdlet, we’re going to focus on Get-AdComputer. Similar to one of the previous cmdlets of the day Get-AdUser, this cmdlet is it’s counterpart in the Active Directory module. Instead of retrieving user objects from Active Directory, this cmdlet finds computers in OUs. The Get-AdComputer Filter Parameter One way to use this cmdlet is to use the Filter parameter. We can use the Filter parameter to search for computers in Active Directory based on their name, for example.

Finding Computers in an OU Perhaps we’re not necessarily concerned with their name but in what OU they’re in. Like the Get-AdUser cmdlet, this cmdlet has a SearchBase parameter we can use to limit the search only to an OU and all of its child OUs. Below I’m finding all of the domain controllers inside of my mylab.local’s Domain Controllers OU.

But what if you’ve got a ton of […]

Read more

Set-Content: The PowerShell Way to Write to a File

Set-Content is one of those core PowerShell cmdlets that I can’t do without. I still remember using VBscript before we could use PowerShell to write to a file. I remember always trying to remember what kind of object I needed to use and the method name. Was it FileSystemObject, FileObject or what? It was a pain! Also, even when I did recall the method name was CreateTextFile, I’d always forget to add True as the second argument. Here’s an example of the monstrosity I’m talking about.

Compare that VBScript with this PowerShell:

Which one do you prefer? I’ll take the PowerShell way! The PowerShell way uses a single cmdlet called Set-Content. This cmdlet allows us to much more easily use PowerShell to write to a file. This PowerShell cmdlet is a built-in cmdlet that has one purpose; to write to a file. It may have some parameters here […]

Read more

Set-ExecutionPolicy: Your Key to Opening PowerShell Scripts

Set-ExecutionPolicy is our next PowerShell cmdlet of the day! This cmdlet is one that most newcomers to PowerShell get familiar with real quick especially if they launch PowerShell on an older operating system. Why? Because PowerShell script execution and any PowerShell module wouldn’t work! A newbie may create a script in the PowerShell ISE, try to execute a PowerShell script and immediately wonder why her script won’t execute. They’d then do a little Googling and find the method to find the applied executio policy, run Get-ExecutionPolicy to find it is restricted. One of the first hurdles everyone new to PowerShell must overcome is figuring out how to just run scripts. Before Windows Server 2012 R2, it was not possible to run any scripts without first opening a PowerShell window and running the PowerShell Set-ExecutionPolicy cmdlet in the PowerShell console. Nowadays, the restrictions have been lifted a little bit but it’s still […]

Read more

Get-AdUser: A Cmdlet a Day

Get-AdUser is our first PowerShell cmdlet for the day! If you’re in IT, chances are you’ve got some implementation of Microsoft’s Active Directory (AD). A huge part of AD is users. Users are what gets assigned to individual employees, service accounts, etc. Get-AdUser is a cmdlet inside of the freely available Remote Server Administration Tools (RSAT) package. Once you have the ActiveDirectory module installed, let’s take a look at the cmdlet we’re here for today! Get-AdUser has one purpose and one purpose only: to give you as many options as possible to either find a specific user object where you already know information about or return lots of users that match specific criteria. Finding an Individual User Account with Get-AdUser If you already know a couple different criteria for a user object already Get-AdUser allows you to find information about a single user. To do so requires knowing one of […]

Read more

Introducing the Cmdlet a Day Series

I’d like to go back to my roots a bit for a series of posts to help the PowerShell newcomer or dust off some of those old cmdlets that you may have forgotten about. I’m starting a series I’m calling a Cmdlet a Day that goes over, in detail, one specific PowerShell cmdlet. These cmdlets can be a default PowerShell cmdlet or could be part of a popular PowerShell module as well. The main point of this series is to help newbies learn PowerShell. I hope it will also spark some ideas for all of you experts out there or perhaps teach everyone a little bit more about a cmdlet you either didn’t realize existed or never took the time to learn it. When I first started, I’d see all of these hundreds (now thousands) of cmdlets available to me and would get overwhelmed. I never knew the right one […]

Read more
1 2 3 4 24