yaxzone
Tehchnologist, Linux user, Code Monkey, Gamer, and more importantly a Husband and a Dad. So you have been warned.
Friday, May 29, 2020
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.
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.
# luis@yaxmail.com - 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
# http://blogs.technet.com/b/heyscriptingguy/archive/2010/07/11/hey-scripting-guy-weekend-scripter-checking-for-module-dependencies-in-windows-powershell.aspx
#####
$AD = "ActiveDirectory"
Function Get-MyModule {
Param([string]$name)
if(-not(Get-Module -name $name)) {
if(Get-Module -ListAvailable | Where-Object { $_.name -eq $name }) {
Import-Module -Name $name
} else {
$false
}
}
}
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*') {
$separator
$WillExpire = [datetime]::FromFileTime((Get-ADUser -Identity $User2Check -Properties "msDS-UserPasswordExpiryTimeComputed")."msDS-UserPasswordExpiryTimeComputed")
write-host "Password for"$User2Check" expires on: "$WillExpire
$separator
} elseif ($VerifyExpiration -like '*True*') {
$separator
write-host "Password does not expire for user: "$User2Check
$separator
}
} else {
$separator
write-host "User provided:"$User2Check", is not in the Active Directory"
$separator
}
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" (http://technet.microsoft.com/en-us/library/cc772200(v=ws.10).aspx).
You can do all kinds of things with it. So, here is how to clone a site, siteA.com to siteB.com, for web apps running in a SAAS environment.
%windir%\system32\inetsrv\appcmd list site "mastersite.com" /config /xml > c:\copy_of_mastersite.com.xml
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 master.com 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 copy_of_mastersite.com to mastersite2.com.xml or whatever you new domain/subdomain is going to be.
%windir%\system32\inetsrv\appcmd add site /in < c:\copy_of_mastersite.com.xml
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 "mastersite2.com" /bindings:http/*:8080:,http/*:80/mastersite2.com,https/*:443:mastersite2.com
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.
Labels:
appcmd,
iis7,
iis7 site clonning,
microsoft iis 7,
web site clonning
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.
If you find it useful, let me know what you think.
#!/bin/sh # 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 yaxzone@yaxmail.com # 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 ***** Set="http://www.flickr.com/photos/crustydolphin/sets/72157618053451592/detail/" # 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 do echo $Set"?page="$PageNumb >> Pages.txt done # This pices gets all the links to the pictures on the pages for ImagesUrl in `cat Pages.txt | awk '{print $1}' | sort -d | uniq` do lynx -dump $ImagesUrl | grep 'in/set-' | awk '{print $2}' | sort -d | uniq >> ImagesUrl.txt done 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` do 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 then File2Download=`cat Image2Download | tail -1` echo $File2Download else File2Download=`cat Image2Download | head -1` echo $File2Download fi 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 done } 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 ComponentsDownload DownloadImages CleanUp 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:
- Gets jokes from the good folks at http://www.randomjoke.com/ (Please support them if you can.)
- It formats the returned joke so it can be printed on the terminal screen
- 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 yaxzone@yaxmail.com
Sunday, January 22, 2012
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 (http://www.levelofindirection.com/journal/2009/10/10/using-a-networked-drive-for-time-machine-backups-on-a-mac.html).
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 -----
#/bin/sh
# Luis Yax - info@yaxmail.com
# This script fixes the below error when setting up TimeMachine on Mac OS X v10.6.8, error 45
clear;
echo -e "\nCurrent Volumes mounted: "
ls -1 /Volumes/ | nl; echo " "
echo "Enter your TimeMachine Volume name (if not sure, just press enter): "
read VolumeNameEntered
ComputerName=`hostname`
ComputerMACAddress=`ifconfig | grep -A 1 'en0' | grep "ether" | awk '{print $2}' | sed 's/://g'`
if [ -z "$VolumeNameEntered" ];
then
echo "VolumeName is empty"
else
MyTimeMachine=$VolumeNameEntered
fi
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:]]}`
clear
if [[ "IfSuccessAnswer" -eq "0" ]] && [[ ! -z "$VolumeNameEntered" ]];
then
echo "Now moving sparsebundle to TimeMachine Volume ..."
echo "Job completed successfully."
else
echo "The following sparsebundle will have to be moved manually to your TimeMachine volume:"
echo "~/Desktop/"$ComputerName"_"$ComputerMACAddress".sparsebundle"
fi
rm /tmp/MyTimeMachineScriptSetup.log
----- Script Ends -----
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 (http://www.levelofindirection.com/journal/2009/10/10/using-a-networked-drive-for-time-machine-backups-on-a-mac.html).
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 -----
#/bin/sh
# Luis Yax - info@yaxmail.com
# This script fixes the below error when setting up TimeMachine on Mac OS X v10.6.8, error 45
clear;
echo -e "\nCurrent Volumes mounted: "
ls -1 /Volumes/ | nl; echo " "
echo "Enter your TimeMachine Volume name (if not sure, just press enter): "
read VolumeNameEntered
ComputerName=`hostname`
ComputerMACAddress=`ifconfig | grep -A 1 'en0' | grep "ether" | awk '{print $2}' | sed 's/://g'`
if [ -z "$VolumeNameEntered" ];
then
echo "VolumeName is empty"
else
MyTimeMachine=$VolumeNameEntered
fi
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:]]}`
clear
if [[ "IfSuccessAnswer" -eq "0" ]] && [[ ! -z "$VolumeNameEntered" ]];
then
echo "Now moving sparsebundle to TimeMachine Volume ..."
echo "Job completed successfully."
else
echo "The following sparsebundle will have to be moved manually to your TimeMachine volume:"
echo "~/Desktop/"$ComputerName"_"$ComputerMACAddress".sparsebundle"
fi
rm /tmp/MyTimeMachineScriptSetup.log
----- Script Ends -----
Labels:
"Apple Time Machine",
"Error 45",
"Network error",
TimeMachine
Subscribe to:
Posts (Atom)