PowerShell one liner to test whether a string is a valid IP address: Function IsIP ($strTest){[Net.IPAddress]::TryParse($strTest,[ref]$null)} This works for both IPv4 and IPv6.
Prompt User to Dot Source an Advanced Function
I have found that users complain that some of my advanced functions appear to do nothing when run. I wrote the following bit to prompt them how to dot source a script: If (($args.Count -eq 0) -and (!($ScriptVar))) { $ScriptName = $MyInvocation.MyCommand.Name.Replace(".ps1","") $commandline = $MyInvocation.InvocationName.trim() if ($commandLine -ne "."){ $myFile = $MyInvocation.MyCommand.Definition.ToString() Write-warning "This script…
Enhanced Mitigation Experience Toolkit (EMET) 4.1 Released
The Microsoft Enhanced Mitigation Experience Toolkit 4.1 has been released. If you are using Windows OS you should be running EMET. Even if you use the default setup, you will gain additional protection against malware. Read the information in the link and install EMET. Highly recommended.
Count Paired Items with PowerShell
This is just a code fragment for something that took me some time to figure out. What I wanted to do is to count a pair of items. The data was coming from a CSV file, and one of the two values is calculated. The code is: #Make arrays the lazy way, splitting string $UserList…
Use Out-Gridview to Select, Sort and Copy Output
PowerShell 3 introduced one of my favorite Cmdlet, Out-Gridview. It allows you to pipe your output to a GUI where you can sort, and add criteria to limit what is displayed. But you can’t use CTRL-C to copy the results. Frustrated? There is an easy answer: gwmi Win32_Process | Out-GridView -PassThru | clip By using…
Delete Inactive User Profiles with PowerShell
Written to replace DelProf, this script deletes inactive user profiles from a local or remote computer. It supports arguments by position, and has a test parameter. If you run it locally, you may supply host name, localhost or “.” The logfile is tab delimited, you may use XLS extension to open in Excel. If you…
Get User’s Email Address from SmartCard with PowerShell
Someone asked me whether I could pull the email address of a user from an inserted SmartCard. I knew I could dump the information in Windows 7 using the CertUtil command and wanted to experiment with parsing information with PowerShell. The code can be very compact: $certInfo = certutil -scinfo -silent | Select-String -Pattern "RFC822"…
Get Last Domain Logon with PowerShell
You all know about lastlogontimestamp, and how AD replicates logon data in a lazy way. As a result, when you want to know the last logon for a user you need to query all the domain controllers in your Active Directory Domain. I found a script by Ahmed Malek on TechNet, but felt that his…
Open a Hyperlink URL from Clipboard
I write scripts when I see a way to automate a task that I find myself doing repetitively. Because I force email to text, I frequently get emails with URLs that have a line break. Occasionally they will have a space, tab or even a greater than sign “>” if forwarded from another source. I…
Enabling ISE and ActiveDirectory module on Windows 2008 R2 Member Server
So, I wrote a pretty cool script and sent it to a co-worker. I wrote it on a Windows 7 PC with the RSAT tools installed. My friend tried to run it on a 2008 R2 server with PowerShell 3.0, but the ActiveDirectory module would not load. I tried to edit the script, but ISE…