Skip to main content

Posts

How to Access all of the Registry Hives with PowerShell

In Windows PowerShell, there is a PSProvider called Registry .  By default, it gives you access to two registry hives. PS C:\> Get-PSDrive -PSProvider Registry   Name          Used (GB)      Free (GB) Provider       Root                                                CurrentLocation ----          ---------      --------- --------      ------------------ HKCU                                  Registry      ...

Find User Accounts That Have Not Been Used

It happens from time to time. You are asked to create an account by Human Resources and then the employee never shows up.  You would expect HR to tell that the account is no longer needed, right?  Worse yet, what if they forget to tell you that the employee was terminated?  Yes, I’ve had to deal with these procedural issues before.  From a technology stand point, there is nothing wrong.  From a security aspect, everything is wrong.  There are two things that you can do to look for these potential problems.  The first is to look for accounts that have not been logged into. Get-ADUser -filter * -Properties LastLogonDate | Where LastLogonDate -eq $null The LastLogonDate property became available to us with Windows Server 2003 SP1.  Essentially, if the value is $null , then the account has not yet been logged into.  You may want to pipe this to Disable-ADAccount .  This will stop an unused account from being used. What about an employe...

Creating a Visual Separator with PowerShell

When I am delivering my PowerShell classes, I often like to provide a transcript of everything that I do on the screen.  This can often be a lot of information.  To help distinguish between different sections or content, I often just place an inline comment on the screen.  Well, I’m changing things a bit.  Below is my code for Show-Separator .  I use it to provide a visual separation from between content.  Here are some examples. PS C:\> Show-Separator -- 04/20/2014 08:41:47 ----------------------------------------------------     PS C:\> Show-Separator "Module 1 - Demo 3" -ColorSet Cyan -- Module 1 - Demo 3 ------------------------------------------------------   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69...

Find all PowerShell Commands with Specific Parameters

My PowerShell class this week had a great idea.  While we were utilizing Get-Command to find commands, someone asked if it was possible to find commands based on their parameters.  I thought that that would be a good idea.  The original code started really simple. 1 2 3 4 5 6 7 8 Function Find-Parameters {     Param (         [ String ] $Parameter     )     Get-Command |     Where-Object { $_ . Parameters . Keys -eq $Parameter } } This code was designed to be placed in their profiles for easy use.  They simple needed to type Find-Parameters and then the parameter name that they were interested in.  Out popped all the commands that contained that parameter. I decided to have a bit more fun with it.  First I turned it into a filtering function that allowed you to search for commands with multiple parameters through the pipeline.  The...