PowerShell eDirectory Group Membership Query

I found my self needing to query eDirectory for all the group objects and their members.  Below is the PowerShell script to accomplish this.  At its core, it is an LDAP query. $ldapAssembly = [System.Reflection.Assembly]::LoadWithPartialName(“System.DirectoryServices.Protocols”); function ldapQuery() { param($hostName,$authUser,$basedn,$filter); $eDirConnect = New-Object System.DirectoryServices.Protocols.LDAPConnection “$hostName”; $eDirConnect.AuthType = [System.DirectoryServices.Protocols.AuthType]::Basic; $password = Read-Host -Prompt “Password” -AsSecureString; $queryCreds = […]

Uninstalling Application Based on UpgradeCode

I recently had the need to uninstall an (MSI-based) application that has a different ProductCode for each release but doesn’t update the ProductCode when it self-updates. However, each version uses the same UpgradeCode. I knew that I could determine the ProductCode that was used to install the application by looking up the UpgradeCode in the […]

Convert File Encoding

On several occasions I have been asked to convert files from their original encoding to something else so another process or system can use it. Below is an example of a simple approach: get-content -path inputFile.txt | out-file -filePath ouputFile.txt -encoding UTF8 If the file to convert is small and your not in a hurry […]

Powershell TCP Port Scan

I had a piece of code to check a TCP port on a given host, and decided I would build a quick port scanner out of it. function portCheck () { param ($hostName,$port); $portTest = (new-object net.sockets.tcpclient); try { $portTest.connect($hostName, $port) } catch {} if ( $portTest.Connected -eq “True”) { echo “$hostName,$port – Success”; $portTest.Dispose(); […]

Monitor eDirectory with Perl

So I found my self in need of monitoring the status of eDirectory.  So I threw the below Perl code together to handle the job. #!/usr/bin/perl use Sys::Hostname $myHost = hostname; $eDirStatus = `/path/eDirectory/bin/ndsstat 2>&1`; if  ( $eDirStatus =~ /.*eDirectory Server is not running.*/) { `echo -e “eDirectory down on $myHost” | mailx -s “eDir […]

Grab a Line

Here is a quick entry on how to grab a specific line from a file using Powershell.  This code will pull the first line out of C:\temp\myFile.txt (Get-Content C:\temp\myFile.txt)[0]; Here’s how to pull the last line. $lineCount = (Get-Content C:\temp\myFile.txt).count; $lineCount–; (Get-Content C:\temp\myFile.txt)[$lineCount];