If you are running as an administrator, it is easy to get the owner associated with a process using PowerShell: Get-Process -IncludeUserName. Get-Process gets information from System.Diagnostics.Process, not WMI. But you can get similar information from WMI, even if you aren’t an administrator. We had a little debate about this in our last Charlotte PowerShell…
Tag: PowerShell
Two Column WPF Form to Select Items or Properties
Many of my scripts are written for other people to do Active Directory reporting. One of my goals in supporting them is to give them as much flexibility in the data returned with the minimum amount of custom coding required. Convert-ADValues (which I will update soon), outputs friendly dates and expanded information for certificates,…
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…
Delete User Profiles Interactively with PowerShell
Last week, one of my administrators was complaining at how involved it was to remove a profile on a remote user’s computer. A little over two years ago, I wrote Delete Inactive Profiles, as a substitute for DelProf for post Windows XP OS. That script is an advanced function, and was designed to remove stale…