Wednesday, August 22, 2012

Get PassWord Expiration date for a Domain Account with #PowerShell

#PowerShell, I recently I switch to it because of work and man, it is indeed a powerfull #scripting language.  This little script basically gets the date of when a password of an #AD (Active Directory) account will expire.

Let me know if you see anything that can be optimized.

I'll post some more little #powershell #scripts that I've been using to make things a bit easier on the admin side.

# - 20120822
# This cripts takes the passed valued and verifies against the AD to confirm it is a SamAccountName
# If determines it is a SamAccountName, it checks what the value is for PasswordNeverExpires atribute 
# If PasswordNeverExpires is False for SamAccountName, it checks when the password will expire

# Get-MyModule function came from the scripting guy
$AD = "ActiveDirectory"
Function Get-MyModule { 
        if(-not(Get-Module -name $name)) { 
            if(Get-Module -ListAvailable | Where-Object { $ -eq $name }) { 
            Import-Module -Name $name 
            } else { 
Get-MyModule -name $AD

$ValueGiven = $args[0]
$User2Check = $ValueGiven.ToUpper()
$VerifyUser = (Get-ADUser -LDAPFilter "(SamAccountName=$User2Check)").SamAccountName
$VerifyExpiration = (Get-ADUser -LDAPFilter "(SamAccountName=$User2Check)" -Properties *).PasswordNeverExpires
$separator = "---------------------------------------------------------"

if ($VerifyUser) {
    # This comparison had to use the "like" operator since $VerifyExpiration has additional invisible characters
    # If you know how to isolate value, I would love to know
    if ($VerifyExpiration -like '*False*') {

    $WillExpire = [datetime]::FromFileTime((Get-ADUser -Identity $User2Check -Properties "msDS-UserPasswordExpiryTimeComputed")."msDS-UserPasswordExpiryTimeComputed")
    write-host "Password for"$User2Check" expires on: "$WillExpire    
    } elseif ($VerifyExpiration -like '*True*') {

    write-host "Password does not expire for user: "$User2Check

} else {

write-host "User provided:"$User2Check", is not in the Active Directory"


Tuesday, April 10, 2012

Clone IIS 7 Web Site - How to

It used to be very easy to clone an IIS web site in IIS 6, old adsutil.vbs script would do just fine for anyone setting large number of web sites in a web server farm.  Now, all your scripts are broken due to the fact that the "admin scripts" for IIS 6 no longer work with IIS 7, thanks a lot Microsoft. Disappointments never stop with that company.

To make this short and simple, now we have "appcmd" (

You can do all kinds of things with it.  So, here is how to clone a site, to, for web apps running in a SAAS environment.

%windir%\system32\inetsrv\appcmd list site "" /config /xml > c:\

You can also cd into inetsrv directory: 

cd c:\Windows\system32\inetsrv and run appcmd from there. 

What the appcmd command is doing up there is simply exporting the configuration of into an .xml file.  Now all you need to do is replace SITE.NAME and SITE.ID in the .xml file.  Additionally, any bindings for the domain name of the new site. Once that is done you are ready to import it.

I would rename to or whatever you new domain/subdomain is going to be.

%windir%\system32\inetsrv\appcmd add site /in < c:\

By the way, if you are serving SSL on the master site and you want your clone site to serve SSL as well, you'll need to tweak a few things, here is an exemple:

appcmd set site "" /bindings:http/*:8080:,http/*:80/,https/*

Basically SSL with host headers, google this more info on that.  I used port 8080 but you can use any other port. Make sure to go back into the IIS manager for this new site and select a new SSL certificate under bindings

Let me know if that helps you.

Friday, February 10, 2012

#shellscript to download #flickr photo sets

This is #shell #script #shellscript that will retrive public sets of #flickr images.  It creates a directory with the name of the flickr user and it moves all the files into that directory.

If you find it useful, let me know what you think.


# A friend asked me to write a script to download a flickr set of images
# that are Publicly available.
# So, here it is, my first attempt
# If you have any questions shoot me an email
# If you are going to be running this script on Linux, make sure to
# uncomment out line 28 and comment out line 29

## Set to download 
# ***** Replace this url with the SET you would like to download *****

# Size of files 
SizeImage="_z.jpg" # This is the medium size
SizeImage1="_b.jpg" # Large size if available

# Creates directory with the name of the user
Dir=`echo $Set | cut -d'/' -f5` 

function ComponentsDownload { # This function gets all the pages number
mkdir -p $Dir
PagesCalc=`lynx -dump $Set | grep 'page' | awk '{print $2}' | sort -d | uniq | cut -d'=' -f2 | sort -n | tail -1`
PagesCalcPlus1=$(expr $PagesCalc + 1)

#for PageNumb in `seq 1 $PagesCalcPlus1` # For Linux usage
for PageNumb in `jot - 1 $PagesCalcPlus1` # For Mac OS X usage


echo $Set"?page="$PageNumb >> Pages.txt


# This pices gets all the links to the pictures on the pages
for ImagesUrl in `cat Pages.txt | awk '{print $1}' | sort -d | uniq` 

lynx -dump $ImagesUrl | grep 'in/set-' | awk '{print $2}' | sort -d | uniq >> ImagesUrl.txt

echo "First part of job done."
echo "Hold on tight ..."

function DownloadImages { # This funcion starts the actual download of the images
for ImageUrl in `cat ImagesUrl.txt | sort -d | uniq`


curl $ImageUrl | grep "url: 'http://" | grep "$SizeImage\|$SizeImage1" | cut -d"'" -f2  > Image2Download 2>&1

WhichFile=`grep '_b.jpg' Image2Download`

if [ ! -z "$WhichFile" ]; # This piece determines which file to download

File2Download=`cat Image2Download | tail -1`
echo $File2Download


File2Download=`cat Image2Download | head -1`
echo $File2Download


wget $File2Download > /dev/null 2>&1
File2Move=`echo $File2Download | cut -d'/' -f5`
mv $File2Move $Dir"/"
rm Image2Download
sleep 1 # Waits 1 second before it downloads the second image


function CleanUp { # Removes the pages where the urls get stored
rm ImagesUrl.txt
rm Pages.txt

# this piece renames the files for the ones that have extra characters
cd $Dir
ls -1 | grep '.jpg?' | while read File; do mv $File `echo $File | cut -d'?' -f1`; done
cd ..

# This executes the above functions

echo "Job done."

Monday, January 23, 2012

A little joke for your day ...

I have written this shell script to get some jokes in my daily routine. If you are like me, you probably open several terminal windows during the day.

If that is the case, how about a little joke to keep it fun.

This script does a few things:

  1. Gets jokes from the good folks at (Please support them if you can.)
  2. It formats the returned joke so it can be printed on the terminal screen
  3. Since some of the jokes are pretty funny, I decided to add functionally to update the status on Adium/Skype with the returned "oneliners" joke

I've tested this with Snow Leopard and Leopard on the Mac, also Ubuntu 11.10 and Ubuntu 11.04 (The Ubuntu part is only for printing on the terminal not Adium/Skype).

In Linux, with the sed command, line 69 and 73 on the script, remove the set of empty "" double quotes.

If you are not going to use the Adium/Skype functionally, feel free to use the other "Joke Categories" which are pretty funny.

Shout me an email if you have any questions

Sunday, January 22, 2012

My beautiful wife ...

My beautiful wife ... by YAXZONE
My beautiful wife ..., a photo by YAXZONE on Flickr.

with built-in flash here...

Tuesday, December 20, 2011

Apple Time Machine and error 45 when using it on a network drive

I just started using Time Machine (Yeah, I know, i'm late to the party) on some Macs I have and to my surprise things did not work from the get go, very un-Apple-like. This occurred on v10.6.8 and v10.5.x.

Anyway, to make it short, I've written a script that fixes this.

Some of the information I pieced together came from this guy's article (

So, if you get the following error, have at it:

Time Machine could not complete the backup.
The backup disk image "/Volumes/*/*.sparsebundle" could not be created (error 45).

----- Script Starts -----
# Luis Yax -
# This script fixes the below error when setting up TimeMachine on Mac OS X v10.6.8, error 45

echo -e "\nCurrent Volumes mounted: "
ls -1 /Volumes/ | nl; echo " "
echo "Enter your TimeMachine Volume name (if not sure, just press enter): "
read VolumeNameEntered
ComputerMACAddress=`ifconfig | grep -A 1 'en0' | grep "ether" | awk '{print $2}' | sed 's/://g'`
if [ -z "$VolumeNameEntered" ];
echo "VolumeName is empty"
echo "sparsebundle being created, hold on tight ..."
hdiutil create -size 320g -type SPARSEBUNDLE -nospotlight -volname "Backup of $ComputerName" -fs "Case-sensitive Journaled HFS+" -verbose ~/Desktop/$ComputerName"_"$ComputerMACAddress.sparsebundle > /tmp/MyTimeMachineScriptSetup.log 2>&1
IfSuccess=`grep "created: " /tmp/MyTimeMachineScriptSetup.log | awk '{print $5}'`
IfSuccessAnswer=`echo ${IfSuccess//[[:space:]]}`
if [[ "IfSuccessAnswer" -eq "0" ]] && [[ ! -z "$VolumeNameEntered" ]];
echo "Now moving sparsebundle to TimeMachine Volume ..."
echo "Job completed successfully."
echo "The following sparsebundle will have to be moved manually to your TimeMachine volume:"
echo "~/Desktop/"$ComputerName"_"$ComputerMACAddress".sparsebundle"
rm /tmp/MyTimeMachineScriptSetup.log

----- Script Ends -----

Saturday, December 17, 2011


_MG_3223 by YAXZONE
_MG_3223, a photo by YAXZONE on Flickr.

Our little "Lady Bug" :)