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 move. Particularly annoying was seeing the CreationTime being more recent than the LastWriteTime attribute. At…
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: #My Computername works anywhere in forest $strFilter = “(&(objectCategory=Computer)(Name=$env:computername))” $objSearcher = New-Object System.DirectoryServices.DirectorySearcher $objSearcher.Filter = $strFilter $searchRootName = [system.directoryservices.activedirectory.forest]::GetCurrentForest().Name.ToString() $SearchRoot = “GC://”+$SearchRootName $objSearcher.SearchRoot…
An Empty Pipe Element is not Allowed Here – Workaround
This code gives you the error, “An Empty Pipe Element is not Allowed Here”: $files = Get-ChildItem foreach ($file in $files) {$file.FullName } | Out-GridView -title “Example” The workaround which solves this problem is to make it an array by enclosing the code in @(), Example: $files = Get-ChildItem @(foreach ($file in $files) {$file.FullName })…
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: $Properties =@” HostName TaskName Task To Run Start Date Start Time “@ $Properties.Split(“`r`n|`r|`n”,[System.StringSplitOptions]::RemoveEmptyEntries) This method uses a regular expression with three different variations of line break, then the .NET method of removing empty lines.
Create an AD Drive for Specified Domain
When you load the Active Directory Module, you get, by default, an Active Directory PSDrive for the current domain. You can avoid the drive from loading by setting $Env:ADPS_LoadDefaultDrive = 0. When writing scripts to export and import AD delegations, connecting to this remote drive became important to me. Here is an example of the…
Update to Dot Source Reminder with Search and Replace
“The pause doesn’t work for me”, said one of my team members about the pause function in my Dot Source Reminder code. We took some time to analyze why and found that his shell settings were different from mine. Instead I decided to focus on whether the code executed inside the ISE. Next was to…
Get MAC Address from IP Address
I got a call last week from a member of one the other teams where I work. He asked, “Do you have a script which will resolve a list of IP Addresses to MAC Addresses?” My answer was, “not yet”. I did a search and found some very convoluted Pinvoke code. I wanted something easier….
Open the PowerShell ISE (and other Programs) with Alternate Credentials
RunAS for PowerShell is pretty easy. This opens the ISE: sl “c:\” $cred = Get-Credential $Prog = “c:\windows\system32\WindowsPowerShell\v1.0\PowerShell_ISE.exe” Start-Process $Prog -Credential $cred
Update GPOs with Newer Version
If you use GPOs to enforce baselines, you may find that your enterprise is moving from version 1.1 to version 1.2 of a GPO. Unfortunately for you, version 1.1 linked in a dozen places. Wouldn’t you rather just you search for version 1.1 and replace it with version 1.2? Use Update-GPOLinks.ps1 to do just that. …
Get All GPOs Linked to an OU
Get-AllGPOsLinkedToOU.ps1 returns a unique list of all GPO’s linked to an OU. You can also run a onelevel or subtree search to get a unique list of linked OUs at or below the selected OU. You are prompted for the domain, and navigate to desired OU.