#!/bin/bash
#Script to check md5sum of iso file against disc in drive
#DEPENDS on md5sum existing in path
#
#script should be called like:
# ./md5check.sh file.iso /dev/dvd
ckFile=$1
ckDrv=$2
echo "Getting file extents..."
fext=$(( $(ls -l $ckFile | awk '{ print $5 }') / 2048 ))
echo "Getting md5sum of file..."
fileMD5sum=`cat $ckFile | md5sum`
echo "Getting md5sum of disc in drive..."
drvMD5sum=`dd if=$ckDrv bs=2048 count=$fext | md5sum`
echo "File md5sum: " $fileMD5sum
echo "Drive md5sum: " $drvMD5sum
if [ "$fileMD5sum" = "$drvMD5sum" ]; then
echo " "
echo "md5sum of" $ckFile "and" $ckDrv "match."
echo " "
else
echo " "
echo "********************************"
echo "******** WARNING!!! **********"
echo "********************************"
echo "** md5sum DOES NOT MATCH!!! ***"
echo "********************************"
echo "********* WARNING!!! **********"
echo "********************************"
echo " "
fi
Saturday, March 26. 2011
compare a burned dvd or cd with iso file in linux
This is something I've been meaning to write for a while. By using this script and md5sum, you can verify that data burned to CD/DVD matches the original ISO file in Linux. It's a bit tricky, as it's not as simple as just running md5sum against /dev/dvd (the whole disc). That's because more than just the data in the ISO is written to the media (finalizing the disc, etc.).
Friday, March 11. 2011
Exchange PowerShell script to sync contacts in an OU with a CSV file
This was an extremely difficult topic to find information on, but very easy to write in Windows PowerShell. It seems a lot of others are syncing contacts in OUs across forests for multi-company organizations or similar. In my case, I'm the email admin at a college and need to populate contacts in our Exchange GAL from a CSV file. We use CSV imports due to the fact that we use multiple mail platforms and export address information from our ERP/SIS system for students.
My old process was to use CSVDE to import the CSV file into the ActiveDirectory OU "Students". However, this process required that I delete all 1,800 or so contacts and then reimport. This was not very elegant. So, after a lot of fruitless searching, I decided to write this script to handle our Student OU that contains only contact objects for the Exchange GAL.
This script first checks the existing contacts, based on email address, against the CSV file. If they exist in the file, great, do nothing, otherwise, delete the contact in the OU. Next, if the file has new contacts to import, import them! The script has two variables up in the "customizations" section that you can change for your specific OU and of course, the path to your CSV file's location. The structure of the CSV file is:
displayName,mail,givenName,sn,mailNickname,Company
The PowerShell (.ps1) script is below for anyone who could benefit from this. Make sure you run it as a user that has access to the OU you're syncing and enjoy!
My old process was to use CSVDE to import the CSV file into the ActiveDirectory OU "Students". However, this process required that I delete all 1,800 or so contacts and then reimport. This was not very elegant. So, after a lot of fruitless searching, I decided to write this script to handle our Student OU that contains only contact objects for the Exchange GAL.
This script first checks the existing contacts, based on email address, against the CSV file. If they exist in the file, great, do nothing, otherwise, delete the contact in the OU. Next, if the file has new contacts to import, import them! The script has two variables up in the "customizations" section that you can change for your specific OU and of course, the path to your CSV file's location. The structure of the CSV file is:
displayName,mail,givenName,sn,mailNickname,Company
The PowerShell (.ps1) script is below for anyone who could benefit from this. Make sure you run it as a user that has access to the OU you're syncing and enjoy!
#
#Exchange 2008 Contact sync with CSV file
#
#Set customizations here
$syncOU="Students"
$importFile="C:\temp\ExchangeImport.csv"
#
#Global Variables
$removeCounter=0
$addCounter=0
#
#Check existing contacts in OU against CSV file, delete if not found
write-host "Checking existing contacts for deletions..."
$existingContacts = get-recipient -resultSize unlimited -organizationalUnit $syncOU -recipientType MailContact |
select -expand EmailAddresses | %{$_.smtpAddress}
$existingContacts | forEach-object -process {
if ($_ -ne $NULL) {
$i = $_
if (import-csv $importFile | where-object {$_.mail -eq $i})
{}
else
{
write-host "Removing contact: " $i
Remove-MailContact -Identity $i -Confirm:$false
$removeCounter++
}
}
}
#
#Check CSV file for new addresses against OU, create if not found
write-host "Checking CSV file for new contacts..."
import-csv $importFile |
forEach-object -process {
if (get-contact -erroraction silentlycontinue -organizationalUnit $syncOU $_.mail)
{}
else
{
write-host "Adding contact from CSV file:"
new-mailContact -Name $.displayName -FirstName $.GivenName -LastName $_.sn `
-Alias $.mailNickname -ExternalEmailAddress $.mail `
-PrimarySmtpAddress $_.mail -OrganizationalUnit $syncOU
set-contact -identity $.mailNickname -WindowsEmailAddress $.mail -Company "$syncOU"
$addCounter++
}
}
#
#Statistics Output
write-host "Attempted to delete " $removeCounter " contacts from the " $syncOU " OU."
write-host "Attempted to add " $addCounter " contacts to the " $syncOU " OU."
(Page 1 of 1, totaling 2 entries)


