One of our admins was running my export and import permissions script, and I thought he had made an error when I looked at an ExtensionAttribute name. Nope. The difference was between the attribute name and the LDAP display name which you see in the Attribute Editor tab from the advanced view of Active Directory…
Convert CSV to Excel with Drag and Drop
Back in 2009, I published Convert CSV files to Excel, a vbscript which converts csv files to xlsx format. Although there is not good way to directly support drag and drop with PowerShell, it can be done with a form. Convert-DroppedCSVsToExcel.ps1 was mostly written as an exercise for me to work with drag and drop…
Get User Lockout Status with PowerShell
Get-UserLockoutStatus.ps1 is an interactive script to get the lockout status of a selected user or all users in a specified domain. It queries each domain controller for non-replicated attributes using a workflow with an inline script for speed. It requires the ActiveDirectory Module.
Is that String a Date?
Test-IsDate is a simple function which tests a string to determine whether it is a date. function Test-IsDate([string]$sDate) { [boolean]($sDate -as [DateTime]) } Test-IsDate ‘Monday, August 13, 2018 1:28:48 PM’ returns True.
Create a Hash Table with AD Domain DNS Root and NetBIOS Names
I frequently get requests to modify or lookup a list of user names in a CSV file where the username is NTDomain\SamAccountName. Get-ADUser will let you use the NT domain as a server name, but in my experience it is slower than using the domain’s FQDN. Before I import the list in my code, I…
Listing (and running) OS Shell Commands with PowerShell
I think I started using Shell commands when I went looking for the startup folder in Windows 8. A post from Jasone’s MSDN blog suggested the easiest way to open it was by typing “Shell:Startup” in from the run box (WIN+R). I became curious about how to enumerate a list of these shortcuts, and how…
Identify an AD object from the SID
Convert-SidToADObject will take an AD SID and return an object containing the object’s name, SamAccountName, Description, type and distinguished name. function Convert-SidToADObject($sid) { $u = [adsi](“LDAP://<SID=” + $sid + “>”) if ($u.SamAccountName) { [psCustomObject]@{ Name = $u.Name.value SamAccountName = $u.samAccountName.value Description = $u.description.value Type = $u.objectclass.Value[1] DistinguishedName = $u.distinguishedName.value } } Else { “Lookup Failed”…
Practical Lessons on WPF Forms and PowerShell
Last weekend I decided that I was finally going to figure out how to stop using Windows Forms, and move to the newer Windows Presentation Foundation (WPF). Some time ago, I had read a WPF blog post from FoxDeploy.com, which shows how you can cut and past code from Windows Visual Studio into their code…
Where am I? Getting the Name of the Currently Executing Function
I almost always debug scripts by stepping through them. But sometimes it is nice to just have a way to write the current function during execution. I use this: write-verbose “In function {0} ” -f $MyInvocation.MyCommand This uses the .NET formatting style, where the contents of the item after -f is placed as a…
Two Ways to Get Mapped Drives with WMI
For years I have been getting mapped drives from WMI using Win32_NetworkConnection. Typical code looks like this in PowerShell: Get-CimInstance -ClassName ‘Win32_NetworkConnection’ | Select LocalName, RemotePath I have been using a product called ExpanDrive to map my cloud storage to drive letters. When I tried to view the drives with Win32_NetworkConnection, I had no results….