izharkhan
asked on
Powershell script
Powershell script to do post sysprep tasks
configure static IP
change server name
add to the domain
activate windows server 2008
configure static IP
change server name
add to the domain
activate windows server 2008
ASKER
Hello Rainer,
Thank you so much for your quick response. i have few following questions
(1) For static ip, how can i add gateway and primary and secondary dns. also is there any way that it will pop up for a box to enter values.
(2) For change name, i would like to run as a script that i can enter a name and it will change and reboot the server
(3) For add domain, need script that will ask to enter domain name and credentials.
(4) For activation, it should ask to enter key and then activate the server.
Thanks
Thank you so much for your quick response. i have few following questions
(1) For static ip, how can i add gateway and primary and secondary dns. also is there any way that it will pop up for a box to enter values.
(2) For change name, i would like to run as a script that i can enter a name and it will change and reboot the server
(3) For add domain, need script that will ask to enter domain name and credentials.
(4) For activation, it should ask to enter key and then activate the server.
Thanks
Hi,
(1) Static IP, gateway and DNS
(2) Server name and reboot
(3) Domain join with credentials
(4) License
HTH
Rainer
(1) Static IP, gateway and DNS
$newStaticIP = Read-Host 'Please enter the static IP'
$newStaticSubnet = Read-Host 'Please enter the subnet mask'
$newGateway = Read-Host 'Please enter the gateway'
$newDNS = Read-Host 'Please enter the DNS server IP'
$wmi = Get-WmiObject win32_networkadapterconfiguration -filter "ipenabled = 'true'"
$wmi.EnableStatic($newStaticIP, $newStaticSubnet)
$wmi.SetGateways($newGateway, 1)
$wmi.SetDNSServerSearchOrder($newDNS)
(2) Server name and reboot
$newComputerName = Read-Host 'Please enter the new computer name'
Rename-Computer -NewName $newComputerName
Write-Host "Local computer will be now rebooted"
Restart-Computer
(3) Domain join with credentials
$username = Read-Host 'Please enter user name (domain\user)'
$pass = Read-Host 'Please enter the password' -AsSecureString
$Cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username,$pass
$domainToJoin = Read-Host 'Please enter the domain to join'
Add-Computer -DomainName $domainToJoin -Credential $Cred
(4) License
$computer = gc env:computername
$key = Read-Host 'Please enter the license key (including the hyphens)'
$service = get-wmiObject -query "select * from SoftwareLicensingService" -computername $computer
$service.InstallProductKey($key)
$service.RefreshLicenseStatus()
HTH
Rainer
ASKER
Hello Rainer,
i checked all the scripts and it work fine. is there any way that you can create one script and do manu to run all these scripts?
example: press 1. static ip, 2. change name .....
That will be great.
thanks Genius :)
i checked all the scripts and it work fine. is there any way that you can create one script and do manu to run all these scripts?
example: press 1. static ip, 2. change name .....
That will be great.
thanks Genius :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
here the parts - as I have no demo environment to test, I would (could) not deliver a fully tested script:
1. Configure static IP
Using the WMI
Open in new window
2. Change Server name
Here you can use the built-in commandlet
http://technet.microsoft.com/en-us/library/hh849792.aspx
Open in new window
3. Join domain
Here you can use the "Add-Computer" commandlet:
http://technet.microsoft.com/en-us/library/hh849798.aspx
Open in new window
4. Activate Windows
From this blog post:
http://blogs.technet.com/b/rgullick/archive/2013/06/13/activating-windows-with-powershell.aspx
Open in new window
HTH
Rainer