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
Subscribe to:
Posts (Atom)