This is the followup to the sysprep.ini file I recently posted. You can think of this as the postinstall.bat file it refers to. This will prompt for IP address settings and then set them. I could also be used for copying down and installing other applications. The way this is written it assumes that DHCP is running after a reboot. You could cut the IP address settings out if you wanted to have DHCP set instead and just use this to install apps.
@echo off
REM ** Ask for IP address and set it as variable IPADDR
set /p IPADDR= Please enter the new IP address
REM ** Ask for Default Gateway set it as variable DEFGATE
set /p DEFGATE= Please enter the new default gateway
REM ** Ask for subnet mask and set it as variable SUBNET
set /p SUBNET= Please enter the new subnet mask
REM ** ask for Primary DNS and set it to variable DNS1
set /p DNS1= Please enter the new default DNS address:
REM ** ask for secondary DNS and set it to variable DNS2
set /p DNS2= Please enter the new secondary DNS address:
REM *** copy install directory ***
REM *** end copy ***
REM *** change IP address ***
echo setting ip address and subnet Mask
netsh int ip set address name = "Local Area Connection" source = static addr=%IPADDR% mask = %SUBNET%
ECHO setting default gateway
netsh int ip set address name = "Local Area Connection" gateway = %DEFGATE% gwmetric=1
echo setting Primary DNS
netsh int ip set dns name = "Local Area Connection" source = static addr = %dns1%
echo setting secondary DNS
netsh int ip add dns name = "Local ARea Connection" addr = %dns2%
echo here is the new settings
netsh int ip show config
REM *** end ip address set ***
shutdown -r -t 01
Wednesday, December 8, 2010
Generate sysprep.ini file on the fly
I use this in some batch files that will generate a sysprep.ini file after a computer name has been entered. This allows for a tech to enter the new computer name at install and let it take care of anything else.
@echo off
set /p PCNAME= Please enter name of PC
if exist c:\sysprep\sysprep.inf del c:\sysprep\sysprep.inf
echo ;SetupMgrTag >> c:\sysprep\sysprep.inf
echo [Unattended] >> c:\sysprep\sysprep.inf
echo OemSkipEula=Yes >> c:\sysprep\sysprep.inf
echo [GuiUnattended] >> c:\sysprep\sysprep.inf
echo AdminPassword="password" >> c:\sysprep\sysprep.inf
echo EncryptedAdminPassword=NO >> c:\sysprep\sysprep.inf
echo AutoLogon=Yes >> c:\sysprep\sysprep.inf
echo AutoLogonCount=1 >> c:\sysprep\sysprep.inf
echo OEMSkipRegional=1 >> c:\sysprep\sysprep.inf
echo TimeZone=10 >> c:\sysprep\sysprep.inf
echo OemSkipWelcome=1 >> c:\sysprep\sysprep.inf
echo [UserData] >> c:\sysprep\sysprep.inf
echo ProductID=Product_key_here >> c:\sysprep\sysprep.inf
echo FullName="Name_here" >> c:\sysprep\sysprep.inf
echo OrgName="Name_here" >> c:\sysprep\sysprep.inf
echo ComputerName=%PCNAME% >> c:\sysprep\sysprep.inf
echo [SetupMgr] >> c:\sysprep\sysprep.inf
echo DistFolder=C:\sysprep\i386 >> c:\sysprep\sysprep.inf
echo DistShare=whistlerdist >> c:\sysprep\sysprep.inf
echo [GuiRunOnce] >> c:\sysprep\sysprep.inf
echo Command0=c:\postinstall.bat >> c:\sysprep\sysprep.inf
echo [Identification] >> c:\sysprep\sysprep.inf
echo JoinDomain=domain_name_here >> c:\sysprep\sysprep.inf
echo DomainAdmin=account_used_to_join_domain >> c:\sysprep\sysprep.inf
echo DomainAdminPassword=password >> c:\sysprep\sysprep.inf
echo MachineObjectOU="OU_you_want_to_place_workstation_in" >> c:\sysprep\sysprep.inf
echo [Networking] >> c:\sysprep\sysprep.inf
echo InstallDefaultComponents=Yes >> c:\sysprep\sysprep.inf
c:\sysprep\sysprep.exe -reseal -mini -quiet -reboot
@echo off
set /p PCNAME= Please enter name of PC
if exist c:\sysprep\sysprep.inf del c:\sysprep\sysprep.inf
echo ;SetupMgrTag >> c:\sysprep\sysprep.inf
echo [Unattended] >> c:\sysprep\sysprep.inf
echo OemSkipEula=Yes >> c:\sysprep\sysprep.inf
echo [GuiUnattended] >> c:\sysprep\sysprep.inf
echo AdminPassword="password" >> c:\sysprep\sysprep.inf
echo EncryptedAdminPassword=NO >> c:\sysprep\sysprep.inf
echo AutoLogon=Yes >> c:\sysprep\sysprep.inf
echo AutoLogonCount=1 >> c:\sysprep\sysprep.inf
echo OEMSkipRegional=1 >> c:\sysprep\sysprep.inf
echo TimeZone=10 >> c:\sysprep\sysprep.inf
echo OemSkipWelcome=1 >> c:\sysprep\sysprep.inf
echo [UserData] >> c:\sysprep\sysprep.inf
echo ProductID=Product_key_here >> c:\sysprep\sysprep.inf
echo FullName="Name_here" >> c:\sysprep\sysprep.inf
echo OrgName="Name_here" >> c:\sysprep\sysprep.inf
echo ComputerName=%PCNAME% >> c:\sysprep\sysprep.inf
echo [SetupMgr] >> c:\sysprep\sysprep.inf
echo DistFolder=C:\sysprep\i386 >> c:\sysprep\sysprep.inf
echo DistShare=whistlerdist >> c:\sysprep\sysprep.inf
echo [GuiRunOnce] >> c:\sysprep\sysprep.inf
echo Command0=c:\postinstall.bat >> c:\sysprep\sysprep.inf
echo [Identification] >> c:\sysprep\sysprep.inf
echo JoinDomain=domain_name_here >> c:\sysprep\sysprep.inf
echo DomainAdmin=account_used_to_join_domain >> c:\sysprep\sysprep.inf
echo DomainAdminPassword=password >> c:\sysprep\sysprep.inf
echo MachineObjectOU="OU_you_want_to_place_workstation_in" >> c:\sysprep\sysprep.inf
echo [Networking] >> c:\sysprep\sysprep.inf
echo InstallDefaultComponents=Yes >> c:\sysprep\sysprep.inf
c:\sysprep\sysprep.exe -reseal -mini -quiet -reboot
Powershell set computer name
I will be posting some powershell scripts that have been found in places that I did not remember. Some have been tweeked by me others have not.
function Set-ComputerName {
param( [switch]$help,
[string]$originalPCName=$(read-host "Please specify the current name of the computer"),
[string]$computerName=$(read-host "Please specify the new name of the computer"))
$usage = "set-ComputerName -originalPCname CurrentName -computername AnewName"
if ($help) {Write-Host $usage;break}
$computer = Get-WmiObject Win32_ComputerSystem -OriginalPCname OriginalName -computername $originalPCName
$computer.Rename($computerName)
}
function Set-ComputerName {
param( [switch]$help,
[string]$originalPCName=$(read-host "Please specify the current name of the computer"),
[string]$computerName=$(read-host "Please specify the new name of the computer"))
$usage = "set-ComputerName -originalPCname CurrentName -computername AnewName"
if ($help) {Write-Host $usage;break}
$computer = Get-WmiObject Win32_ComputerSystem -OriginalPCname OriginalName -computername $originalPCName
$computer.Rename($computerName)
}
powershell set ipaddress
I will be posting some powershell scripts that have been found in places that I did not remember. Some have been tweeked by me others have not.
function Set-IPAddress {
param( [string]$networkinterface,
[string]$ip,
[string]$mask,
[string]$gateway,
[string]$dns1,
[string]$dns2,
[string]$registerDns = "TRUE"
)
#Start writing code here
$dns = $dns1
if($dns2){$dns ="$dns1,$dns2"}
$index = (gwmi Win32_NetworkAdapter | where {$_.netconnectionid -eq $networkinterface}).InterfaceIndex
$NetInterface = Get-WmiObject Win32_NetworkAdapterConfiguration | where {$_.InterfaceIndex -eq $index}
$NetInterface.EnableStatic($ip, $mask)
$NetInterface.SetGateways($gateway)
$NetInterface.SetDNSServerSearchOrder($dns)
$NetInterface.SetDynamicDNSRegistration($registerDns)
}
function Set-IPAddress {
param( [string]$networkinterface,
[string]$ip,
[string]$mask,
[string]$gateway,
[string]$dns1,
[string]$dns2,
[string]$registerDns = "TRUE"
)
#Start writing code here
$dns = $dns1
if($dns2){$dns ="$dns1,$dns2"}
$index = (gwmi Win32_NetworkAdapter | where {$_.netconnectionid -eq $networkinterface}).InterfaceIndex
$NetInterface = Get-WmiObject Win32_NetworkAdapterConfiguration | where {$_.InterfaceIndex -eq $index}
$NetInterface.EnableStatic($ip, $mask)
$NetInterface.SetGateways($gateway)
$NetInterface.SetDNSServerSearchOrder($dns)
$NetInterface.SetDynamicDNSRegistration($registerDns)
}
Powershell join domain
I will be posting some powershell scripts that have been found in places that I did not remember. Some have been tweeked by me others have not.
function Set-Domain {
param( [switch]$help,
[string]$domain=$(read-host "Please specify the domain to join"),
[System.Management.Automation.PSCredential]$credential = $(Get-Crdential)
)
$usage = "`$cred = get-credential `n"
$usage += "Set-AvaDomain -domain corp.avanade.org -credential `$cred`n"
if ($help) {Write-Host $usage;exit}
$username = $credential.GetNetworkCredential().UserName
$password = $credential.GetNetworkCredential().Password
$computer = Get-WmiObject Win32_ComputerSystem
$computer.JoinDomainOrWorkGroup($domain ,$password, $username, $null, 3)
}
function Set-Domain {
param( [switch]$help,
[string]$domain=$(read-host "Please specify the domain to join"),
[System.Management.Automation.PSCredential]$credential = $(Get-Crdential)
)
$usage = "`$cred = get-credential `n"
$usage += "Set-AvaDomain -domain corp.avanade.org -credential `$cred`n"
if ($help) {Write-Host $usage;exit}
$username = $credential.GetNetworkCredential().UserName
$password = $credential.GetNetworkCredential().Password
$computer = Get-WmiObject Win32_ComputerSystem
$computer.JoinDomainOrWorkGroup($domain ,$password, $username, $null, 3)
}
Batch file menu with options
A good template for a batch file that prompts you for a menu choice.
@echo off
:start
cls
set /p userinp=choose a number(1-6):
set userinp=%userinp:~0,1%
if "%userinp%"=="1" goto 1
if "%userinp%"=="2" goto 2
if "%userinp%"=="3" goto 3
if "%userinp%"=="4" goto 4
if "%userinp%"=="5" goto 5
if "%userinp%"=="6" goto 6
echo invalid choice
goto start
:1
(do stuff here)
goto end
:2
(do more stuff here)
goto end
:3
stuff
goto end
etc.
:end
pause>nul
@echo off
:start
cls
set /p userinp=choose a number(1-6):
set userinp=%userinp:~0,1%
if "%userinp%"=="1" goto 1
if "%userinp%"=="2" goto 2
if "%userinp%"=="3" goto 3
if "%userinp%"=="4" goto 4
if "%userinp%"=="5" goto 5
if "%userinp%"=="6" goto 6
echo invalid choice
goto start
:1
(do stuff here)
goto end
:2
(do more stuff here)
goto end
:3
stuff
goto end
etc.
:end
pause>nul
Easy Windows Ping Log
This will output to a file c:\temp\pinglog.txt. The ping is run every 30 seconds and returns 10 pings at a time.
@echo off
:START
echo ***Start*** >> c:\temp\pinglog.txt
date/t >> c:\temp\pinglog.txt
time/t >> c:\temp\pinglog.txt
ping lookout.temp.com -n 10 >> c:\temp\pinglog.txt
echo ***End*** >> c:\temp\pinglog.txt
@ping 127.0.0.1 -n 30 -w 1000 > nul
goto START
@echo off
:START
echo ***Start*** >> c:\temp\pinglog.txt
date/t >> c:\temp\pinglog.txt
time/t >> c:\temp\pinglog.txt
ping lookout.temp.com -n 10 >> c:\temp\pinglog.txt
echo ***End*** >> c:\temp\pinglog.txt
@ping 127.0.0.1 -n 30 -w 1000 > nul
goto START
Thursday, September 2, 2010
Set default home page for Firefox for all users
To set the default home page for Firefox edit the file c:\Program Files\Mozilla Firefox\browserconfig.properties
Here you can set its default home page and the revert to default home page!
Here you can set its default home page and the revert to default home page!
Friday, August 6, 2010
simple log file
example of some commands to include in a bash script that will write out to a file for logging.
#!/bin/bash
today=$(date +%Y%m%d)
echo "the script ran at" $today >> home.txt
#!/bin/bash
today=$(date +%Y%m%d)
echo "the script ran at" $today >> home.txt
Thursday, August 5, 2010
Thursday, July 8, 2010
Automated Nessus scan from command line.
This handy little script will run a nessus scan against a IP range. I use this in a crontab to run automated scans and dump the results into a directory with a file name that has a time stamp in it.
Make sure that you have a config for your scan already done (this is used for the Nessus_scan_config below). Put your ranges for IP's in the text_file_of_scan_ranges.txt (ie 192.168.1.1-192.168.1.254).
#!/bin/sh
today=$(date +%Y%m%d)
/opt/nessus/bin/nessus -c /opt/nscans/configs/Nessus_scan_config -xq nessus.server 1241 username password /opt/nscans/targets/text_file_of_scan_ranges.txt /opt/nscans/reports/IP_range-$today.html
mkdir /directory_you_want_scans_in/$today
mv /opt/nscans/reports/IP_range-$today.html /directory_you_want_scans_in/$today
Make sure that you have a config for your scan already done (this is used for the Nessus_scan_config below). Put your ranges for IP's in the text_file_of_scan_ranges.txt (ie 192.168.1.1-192.168.1.254).
#!/bin/sh
today=$(date +%Y%m%d)
/opt/nessus/bin/nessus -c /opt/nscans/configs/Nessus_scan_config -xq nessus.server 1241 username password /opt/nscans/targets/text_file_of_scan_ranges.txt /opt/nscans/reports/IP_range-$today.html
mkdir /directory_you_want_scans_in/$today
mv /opt/nscans/reports/IP_range-$today.html /directory_you_want_scans_in/$today
Tuesday, July 6, 2010
Delete files and folders older then 30 days
Just stumbled on this function and had a need to delete temp files that were 30 days old. This works great and I split it out to delete sub folders as well!
@echo off
rem ##### Script deletes files and folders older then 30 days #####
echo deleting files older then 30 days
rem ##### this checks and deletes files that are older then 30 days #####
rem ##### in server 2008 if you delete files first then the date stamp changes on directories so directory delete is done first #####
forfiles /p "c:\temp" /s /d -0 /c "cmd /C del @FILE /q"
rem ##### this checks and deletes directories and sub directories that are older then 30 days #####
ForFiles /P "c:\temp" /D -0 /C "cmd /c if @isdir==TRUE RD /Q /S @FILE "
@echo off
rem ##### Script deletes files and folders older then 30 days #####
echo deleting files older then 30 days
rem ##### this checks and deletes files that are older then 30 days #####
rem ##### in server 2008 if you delete files first then the date stamp changes on directories so directory delete is done first #####
forfiles /p "c:\temp" /s /d -0 /c "cmd /C del @FILE /q"
rem ##### this checks and deletes directories and sub directories that are older then 30 days #####
ForFiles /P "c:\temp" /D -0 /C "cmd /c if @isdir==TRUE RD /Q /S @FILE "
Friday, July 2, 2010
bash script to create incremental multiple lines in a file
I used this script to create a default file for pxelinux.cfg. It could be used for anything that needs almost identical lines added to a file. In this instance I have multiple esx servers and if I want to install/re-install them using a pxe boot environment all I need to do is select the correct server and off I go!
#!/bin/bash
for i in {001..999}
do
echo "label $i" >> default
echo "menu label $i" >> default
echo "kernel esx/vmlinuz" >> default
echo "append initrd=initrd.img vmkopts=debugLogToSerial:1 mem=512M quiet ks=http://IP_address/kickstart_file" >> default
done
#!/bin/bash
for i in {001..999}
do
echo "label $i" >> default
echo "menu label $i" >> default
echo "kernel esx/vmlinuz" >> default
echo "append initrd=initrd.img vmkopts=debugLogToSerial:1 mem=512M quiet ks=http://IP_address/kickstart_file" >> default
done
Friday, June 11, 2010
Curl to pull files from websites.
How to download content via a script from a website. I use this to pull configs for ESX servers:
curl "http://some_website_name/filename[1-100]" -o "newname#1.html";
curl "http://some_website_name/filename[1-100]" -o "newname#1.html";
Tuesday, May 11, 2010
Landesk local schedular restart
Found this here and it works well in a pinch:
http://community.landesk.com/support/thread/4648
: This script will delete the clients landesk database, recreate it, validate it and clean up
: old xml files/ Any xml files that are still required will repopulate as needed
: this is also good at fixing portal and other policy issues
cmd /c del "c:\documents and settings\all users\application data\landesk\managementsuite\database" /q
del "C:\Documents and Settings\All Users\Application Data\LANDesk\ManagementSuite\landesk\files" /q
del "C:\Documents and Settings\All Users\Application Data\vulScan\*.xml" /q
del "C:\Program Files\LANDesk\LDClient\sdmcache\landesk\files\*.xml" /q
net stop "Landesk Policy Invoker"
"c:\program files\landesk\ldclient\clientdbutil.exe" /create
"c:\program files\landesk\ldclient\clientdbutil.exe" /validate
net start "Landesk Policy Invoker"
"c:\program files\landesk\ldclient\policy.sync.exe"
"c:\program files\landesk\ldclient\policy.client.invoker.exe"
EXIT /B 0
http://community.landesk.com/support/thread/4648
: This script will delete the clients landesk database, recreate it, validate it and clean up
: old xml files/ Any xml files that are still required will repopulate as needed
: this is also good at fixing portal and other policy issues
cmd /c del "c:\documents and settings\all users\application data\landesk\managementsuite\database" /q
del "C:\Documents and Settings\All Users\Application Data\LANDesk\ManagementSuite\landesk\files" /q
del "C:\Documents and Settings\All Users\Application Data\vulScan\*.xml" /q
del "C:\Program Files\LANDesk\LDClient\sdmcache\landesk\files\*.xml" /q
net stop "Landesk Policy Invoker"
"c:\program files\landesk\ldclient\clientdbutil.exe" /create
"c:\program files\landesk\ldclient\clientdbutil.exe" /validate
net start "Landesk Policy Invoker"
"c:\program files\landesk\ldclient\policy.sync.exe"
"c:\program files\landesk\ldclient\policy.client.invoker.exe"
EXIT /B 0
NTP Query Program
I work with a lot of slow network connections, I know lucky me. Here is a command that you can use in ESX to allow you to test your NTP connectivity. This is a regular Linux command as well. Use the "timeout value" if you need to add a length of time before a timeout occurs.
ntpq -p -c "timeout 5000" timeserver_name
ntpq -p -c "timeout 5000" timeserver_name
Wednesday, May 5, 2010
cron for tcpdump script
Recently I needed to sniff some traffic at one of my remote data centers. I brought up an old box with linux and needed to capture some traffic every 15 minutes.
This script will create a file with a date and time for the name then start dumping tcpdump data to it. Here is my script that I used to grab the traffic:
#!/bin/bash
killall tcpdump
var=$(date +%G%m%d-%k%M)
/usr/sbin/tcpdump -i eth0 -C 10 -w /home/user/$var.txt
Since the first line of the script kills any tcpdump processes that are currently running, I just set the crontab to run every 15 minutes, it will kill the last tcpdump and create a new file and start the process all over again.
Here is the crontab statement:
00,15,30,45 * * * * /path_to_crantab.sh
This script will create a file with a date and time for the name then start dumping tcpdump data to it. Here is my script that I used to grab the traffic:
#!/bin/bash
killall tcpdump
var=$(date +%G%m%d-%k%M)
/usr/sbin/tcpdump -i eth0 -C 10 -w /home/user/$var.txt
Since the first line of the script kills any tcpdump processes that are currently running, I just set the crontab to run every 15 minutes, it will kill the last tcpdump and create a new file and start the process all over again.
Here is the crontab statement:
00,15,30,45 * * * * /path_to_crantab.sh
expand virtual hard disk of a guest in ESX 4 part II
A while back I wrote about expanding virtual hard drives. The ESX side of things was very slick but the windows side was definitely not. Too bad my ESX 4 class was not a month earlier! There I learned about a free utility from dell called Extpart.exe.
This handy little gem will expand 2000, XP, and 2003 windows partitions (including boot partitions) on the fly! It would have saved me tons of time over the method I was using with gparted and rebooting the guest boxes.
This handy little gem will expand 2000, XP, and 2003 windows partitions (including boot partitions) on the fly! It would have saved me tons of time over the method I was using with gparted and rebooting the guest boxes.
vCenter lesson learned
I discovered last night a very important lesson. the ODBC connections that are used for vCenter that points to an external database are not dynamic. By dynamic I mean trying to change the ODBC pointer in windows will not change the ODBC settings for vCenter! So after going through the register I discovered that when vCenter installs it takes the username and encrypts the current password. What this means is that if you change the ODBC username and/or password vCenter will still try to use the info it detected at install.
I am sure there was a way to change this but due to other issues I was fighting on my vCenter server and changes to our database server a reinstall of vCenter was done. This did correct the issue. One other note vCenter is smart enough when you reinstall to detect a currently used database and asks if you want to use it or create a new one.
I am sure there was a way to change this but due to other issues I was fighting on my vCenter server and changes to our database server a reinstall of vCenter was done. This did correct the issue. One other note vCenter is smart enough when you reinstall to detect a currently used database and asks if you want to use it or create a new one.
Monday, May 3, 2010
Check uptime on a windows 2000, XP, 2003 box
Check uptime with Windows 2000, XP, 2003.
1. Go to "Start" -> "Run".
2. Write "CMD" and press on "Enter" key.
3. Write the command "net statistics server" and press on "Enter" key.
4. The line that start with "Statistics since …" provides the time that the server was up from.
* The command "net stats srv" can be use instead.
1. Go to "Start" -> "Run".
2. Write "CMD" and press on "Enter" key.
3. Write the command "net statistics server" and press on "Enter" key.
4. The line that start with "Statistics since …" provides the time that the server was up from.
* The command "net stats srv" can be use instead.
Thursday, April 22, 2010
delete lost snapshots
A very useful trick I learned today. If you have taken a snapshot of a virtual machine and the snapshot manager does not report that the guest does indeed have a snapshot ( ie a delta disk) then you can do the following to remove it. Take another snapshot of the guest. Then in snapshot manager delete all snapshots. Once the second snapshot is taken it now shows in snapshot manager and all the snapshots can be removed!
Tuesday, April 20, 2010
expand virtual hard disk of a guest in ESX 4
The full path must be specified or the command issued in the directory that the .vmdk file is located.
vmkfstools -X 1000m /vmfs/volumes/datastore/vmguest_name/vmguest_name.vmdk
UPDATE:
After wasting a couple of hours trying to figure out why this won't work I have the answer. the -X size is the total size of the disk not how much you want to expand it by! So the correct syntax should look like this:
vmkfstools -X 25000m /vmfs/volumes/datastore1/vmguest_name/vmquest_name.vmdk
vmkfstools -X 1000m /vmfs/volumes/datastore/vmguest_name/vmguest_name.vmdk
UPDATE:
After wasting a couple of hours trying to figure out why this won't work I have the answer. the -X size is the total size of the disk not how much you want to expand it by! So the correct syntax should look like this:
vmkfstools -X 25000m /vmfs/volumes/datastore1/vmguest_name/vmquest_name.vmdk
Monday, April 19, 2010
Sophos antivirus won't install correctly on Windows 7
Sophos returns this error when trying to install on windows 7:
80070035 Could not start installation program on the computer. The network path was not found.
The fix is to enable the remote registry service in the control panel -> services or run services.msc
Go back to the console and re-run the protect computers again!
80070035 Could not start installation program on the computer. The network path was not found.
The fix is to enable the remote registry service in the control panel -> services or run services.msc
Go back to the console and re-run the protect computers again!
Monday, April 12, 2010
VMware ESX disk usage from command line
Even though ESX is based on Red Hat Linux a normal df -h does not show the amount of disk space used on the data stores. However if you use vdf -h you will get the human readable version of the output.
vdf -h
vdf -h
Thursday, April 8, 2010
copy to and from samba using ESX
You can mount samba shares ( windows or linux CIFS/samba) from an ESX box. This comes in very handy! I use it to copy on and off vmdk files when needed. Below is a example of the script I use for this. It is meant for ESX4. Earlier versions are slightly different.
#!/bin/bash
########################################################
#script to copy vmdk file to local datastore
########################################################
# enable samba client
esxcfg-firewall -e smbClient
##########################################
#make mount directory
##########################################
echo making directory /mnt/copy
mkdir /mnt/copy
###########################################
#mount samba share
##########################################
echo mounting directory to copy .vmdk file
mount -t cifs //ip or name/share /mnt/copy/ -o username=username,password=password
##########################################
#copy .vmdk files
#########################################
cp /mnt/copy/*.vmdk /vmfs/volumes/LocalStorage1/guestvm/
echo vmdk files have been copied.
#########################################
#unmount samba share
########################################
echo unmounting /mnt/copy
umount /mnt/copy
########################################################
#END script to copy vmdk file to local datastore
########################################################
Here are a couple of good links to talk about this topic:
Using Samba shares with vcbRestore on ESX Server Service Console using domain logins
Cannot mount Windows share in ESX 4.x with a mount_data version is not supported error
Connecting to a CIFS Share on a Windows Server from the Service Console
#!/bin/bash
########################################################
#script to copy vmdk file to local datastore
########################################################
# enable samba client
esxcfg-firewall -e smbClient
##########################################
#make mount directory
##########################################
echo making directory /mnt/copy
mkdir /mnt/copy
###########################################
#mount samba share
##########################################
echo mounting directory to copy .vmdk file
mount -t cifs //ip or name/share /mnt/copy/ -o username=username,password=password
##########################################
#copy .vmdk files
#########################################
cp /mnt/copy/*.vmdk /vmfs/volumes/LocalStorage1/guestvm/
echo vmdk files have been copied.
#########################################
#unmount samba share
########################################
echo unmounting /mnt/copy
umount /mnt/copy
########################################################
#END script to copy vmdk file to local datastore
########################################################
Here are a couple of good links to talk about this topic:
Using Samba shares with vcbRestore on ESX Server Service Console using domain logins
Cannot mount Windows share in ESX 4.x with a mount_data version is not supported error
Connecting to a CIFS Share on a Windows Server from the Service Console
Saturday, April 3, 2010
Clear and Add network printers
Here is a handy VB script that I have cobbled together. Some from the web, etc.
set net = CreateObject ("WScript.Network")
'deletes all network printers
Set clPrinters = net.EnumPrinterConnections
For i = 0 to clPrinters.Count - 1 Step 2
clPrinters.Item(i)& " " & i+1
net.RemovePrinterConnection clPrinters.Item(i+1), true
Next
'maps new printers.
net.AddWindowsPrinterConnection "\\print_server_name\printer name", "description"
net.AddWindowsPrinterConnection "\\print_server_name\printer name", "description"
net.AddWindowsPrinterConnection "\\print_server_name\printer name", "description"
net.SetDefaultPrinter "\\print_server_name\printer name"
Wscript.Quit
set net = CreateObject ("WScript.Network")
'deletes all network printers
Set clPrinters = net.EnumPrinterConnections
For i = 0 to clPrinters.Count - 1 Step 2
clPrinters.Item(i)& " " & i+1
net.RemovePrinterConnection clPrinters.Item(i+1), true
Next
'maps new printers.
net.AddWindowsPrinterConnection "\\print_server_name\printer name", "description"
net.AddWindowsPrinterConnection "\\print_server_name\printer name", "description"
net.AddWindowsPrinterConnection "\\print_server_name\printer name", "description"
net.SetDefaultPrinter "\\print_server_name\printer name"
Wscript.Quit
Friday, April 2, 2010
VMware ESX 4 Kickstart setup
After a quite a long process of trying to find a way of taking the human error out of the equation while provisioning an ESX server my colleagues and I have come up with way that not only makes tracking a large ESX environment but allows for quick recover as well.
Before I document what we did a little primer on how ESX and kickstart files work should be in order. We actually use a bootable media such as a DVD or USB stick to start the deployment but PXE environments would work for this as well. This example will be using a USB thumb drive to start things off. The Thumb drive has been made bootable by a process of formatting it to a FAT32 file system and in fdisk making it bootable. Then we use syslinux to give us the boot to kickstart process. Syslinux provides a file called syslinux.cfg. By editing that file and appending a ks=http://somewebsite.com/ks.cfg.php?server=xxx line to the end of the initrd statement ( don't worry I will post an example in a little bit ) we are able to direct the kernel to look for kickstart file to read and process.

With these few lines of code and the contents of the VMware install CD copied to the USB drive we are able to now interact with a web page that will be dynamically generated with all the options for the new ESX server.
The kickstart file is actually a php web page. With the proper formatting of the page and a database query added to retrieve the correct fields we are ready to go. What this gives us is the at the heart of this. By having things like the server name, all network settings, drive partitions, root password, and time zone populated by the database we can not only manage and expand as needed our server information but be able to pull them on the fly when we need to re install a server or install a new one. Also the kickstart file allows for a post install section that can be executed after ESX is installed and the server has rebooted into a live ESX environment. This is quite powerful and allows for even greater flexibility. Plus by having this in one place all you need to do is maintain the code in one spot for every server!
I will post a copy of my kickstart file soon so that you can see how much work can be done with one file. Now I only need to enter the server name and let this handle the rest of the configuration for me!
Before I document what we did a little primer on how ESX and kickstart files work should be in order. We actually use a bootable media such as a DVD or USB stick to start the deployment but PXE environments would work for this as well. This example will be using a USB thumb drive to start things off. The Thumb drive has been made bootable by a process of formatting it to a FAT32 file system and in fdisk making it bootable. Then we use syslinux to give us the boot to kickstart process. Syslinux provides a file called syslinux.cfg. By editing that file and appending a ks=http://somewebsite.com/ks.cfg.php?server=xxx line to the end of the initrd statement ( don't worry I will post an example in a little bit ) we are able to direct the kernel to look for kickstart file to read and process.
With these few lines of code and the contents of the VMware install CD copied to the USB drive we are able to now interact with a web page that will be dynamically generated with all the options for the new ESX server.
The kickstart file is actually a php web page. With the proper formatting of the page and a database query added to retrieve the correct fields we are ready to go. What this gives us is the at the heart of this. By having things like the server name, all network settings, drive partitions, root password, and time zone populated by the database we can not only manage and expand as needed our server information but be able to pull them on the fly when we need to re install a server or install a new one. Also the kickstart file allows for a post install section that can be executed after ESX is installed and the server has rebooted into a live ESX environment. This is quite powerful and allows for even greater flexibility. Plus by having this in one place all you need to do is maintain the code in one spot for every server!
I will post a copy of my kickstart file soon so that you can see how much work can be done with one file. Now I only need to enter the server name and let this handle the rest of the configuration for me!
Subscribe to:
Posts (Atom)