Tag Archives: Powershell Scriptlets

PowerShell Get Column Names for a CSV File

Get-Member doesn’t always show you what is under the hood for an object.  For that you need the .PSObject property.  Here PSObject.Properties contains CSV column names

Posted in PowerShell, Scriptlets | Tagged | Leave a comment

Powershell Date LDAP filters

This snippet can be used for easier date formatting when using an LDAP date filter with PowerShell.  This demonstrates how to get users created within the previous 30 days using LDAP:

 

Posted in Active Directory, PowerShell, Scripting, Scriptlets | Tagged , | Leave a comment

PowerShell Pause with Progress Bar

This snippet of PowerShell was written to have show users something more interesting than “Sleeping for 15 seconds” in a script.  Notice that I splat the progress parameters.

Posted in PowerShell, Scripting, Scriptlets | Tagged | Leave a comment

Fix Creation Date Later than Date Modified with PowerShell

A weird and annoying thing happened to my home directory at work when it was moved from Windows to a storage appliance. The file CreationTime was lost on all the files and was set to the date of the data … Continue reading

Posted in PowerShell, Scripting, Scriptlets, Windows Administration | Tagged , , | Leave a comment

OU of Current PC from anywhere in the Forest

There are a lot of ways to get the OU of the current computer, but most don’t work if you are outside your home domain. This code does, without requiring AD cmdlets:

Update: 9/23/2017: You can also get this … Continue reading

Posted in Active Directory, Scripting, Scriptlets | Tagged , | Leave a comment

An Empty Pipe Element is not Allowed Here – Workaround

This code gives you the error, “An Empty Pipe Element is not Allowed Here”:

The workaround which solves this problem is to make it an array by enclosing the code in @(), Example:

Posted in PowerShell, Scriptlets | Tagged | Leave a comment

Split a List and Remove Empty Lines with PowerShell

I often have lists where I have to split the list, and remove empty lines.  This is how I do it:

This method uses a regular expression with three different variations of line break, then the .NET method of … Continue reading

Posted in PowerShell, Scripting, Scriptlets | Tagged | Leave a comment

Export to HTML with Style Sheet Header

 

This a modification of something I picked up on the web.  It allows you to export to an HTML file with a centered table and centered title.  Any number of properties in the data are made into auto-sized … Continue reading

Posted in PowerShell, Scripting, Scriptlets | Tagged , | Leave a comment

A Dot Source Reminder for Advanced Functions

One of the problems with writing advanced functions is that new PowerShell users think that they don’t do anything.  Frankly, I couldn’t figure out a way to get a notification to work, so I reached out to the sponsor for … Continue reading

Posted in PowerShell, Scripting, Scriptlets | Tagged , , , | Leave a comment

Fix User’s Home Directory Permissions with Take Ownership

Fix-HomeDrivePerms.ps1 is a PowerShell script which attempts to reset folder security when the permissions are really hosed.  It uses a take ownership function, Set-Owner, by Boe Prox, instead of takeown.exe, but does shell out to iCacls.exe.  I wrote this to … Continue reading

Posted in PowerShell, Scripting, Scriptlets, Security, Windows Administration | Tagged , | Leave a comment