Today I created a PowerShell script to get a list of all the WebLogic domains in all the in house development servers. This was needed because it was observed that there were a lot of unattended Weblogic domains left unused after their initial use.

These are the steps

  1. Collect folder paths of WebLogic domains (8.1 and 10.3)
  2. Check for a specific folder naming convention, one for each of 8.1 domains and 10.3 domains
  3. Write to log file for later perusal
function ln ($n,$flag) {
    "."*$n+$flag
}

function wait ($n) {
    start-sleep -s $n
}

$filedate = Get-Date uformat %m%d%Y-%H%M%S
$lf = "C:\Documents and Settings\banimesh\ps\logs\wldomain\"
$logfile  = "$lf"+"wld-"+"$filedate+"+".log"
$appsrv = @(gc config\apps.txt)

$bea8a  = "c$\bea81sp6\user_projects\domains"
$bea8b  = "d$\bea81sp6\user_projects\domains"
$bea10a = "c$\bea103\user_projects\domains"
$bea10b = "d$\bea103\user_projects\domains"

$bea8paths  = @();
$bea10paths = @();

for($i=0;$i -lt $appsrv.length; $i++) 
{
    $bea8paths += "\\$($appsrv[$i])\$($bea8a)\"
    $bea10paths += "\\$($appsrv[$i])\$($bea10a)\"
    $bea8paths += "\\$($appsrv[$i])\$($bea8b)\"
    $bea10paths += "\\$($appsrv[$i])\$($bea10b)\"
}

$eight = (gci $bea8paths -ea 0 | ?{$_.psiscontainer})
$ten = (gci $bea10paths -ea 0 | ?{$_.psiscontainer})

ln 100 BEGIN
write-host "Retrieving all Weblogic domains.."

wait 3

ln 75 PROCESSING
write-host "Listing Weblogic 8.1 domains..."

foreach($domain in $eight)
{
    if($domain -match "^\boldconvention.*prod\b\Z|^\boldconvention.*test\b\Z") 
    { 
        $domain.fullname >> $logfile
    }
}

wait 3

ln 75 PROCESSING
write-host "Listing Weblogic 10.3 domains..."

foreach($domain in $ten)
{
    if($domain -match "^\bnewconvention.*prod\b\Z|^\bnewconvention.*test\b\Z") 
    { 
        $domain.fullname >> $logfile
    }
}

wait 5

ln 100 END

The ln function would just draw a dotted line with a status message added at the end.

ln 25 PROCESSING

would give us

.........................PROCESSING

The begin and end messages are given higher number so as to create a visual convenience.

..................................................BEGIN
# other output
.........................PROCESSING
# other output
# other output
..................................................END