I am building a script to build VM's auto magicly when as I import the relevent information from a csv file.I have the newest version of PowerCli, I am trying to build Sever 2012 r2 servers from a template. I have tried serveral OsCustomizationSpec (OCS)'s in hopes of getting something to work, but I have had no luck so far. In VCenter, it shows it applying the OCS, but it doesn't apear to have any impact on the server. I have turned off UAC since last time I tried it so maybe that will make a difference. I am running ESXi 5.1 Update2, just to try to give all the info neccessary. Idealy, I would like it to sysprep, set the IP's, change the computer name and join the server to the domain. That's all!!! lol I have the book "VMware vSphere PowerCLI Reffernece, Automating vSphere Administration, I walked through it step by step. This newest version of PowerCli doesn't seem to have the x86 limitation that earlier versions of PowerCli did. I have tried so many different things, I am not sure what to put up as a place to start.
# Save the credential object with permission to join the domain.
$DomainCredentials = Get-Credential 'domain\testername'
# Clone our Spec adding the domain information.
$Spec = Get-OSCustomizationSpec 'Windows Server 2012 R2'
$Spec += Get-OSCustomizationNicMapping -Spec $Spec
#$Spec | select *
# Get our VM
# Change network settings
Get-VM BigServername | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName nic-172.16.25-VLAN225 -Connected:$true `
-Confirm:$false | out-null
# Shut down guest to make change.
Shutdown-VMGuest -VM $VM -Confirm:$false | out-null
# Wait while guest shuts down
While ($vm.ExtensionData.Runtime.PowerState -ne ‘poweredOff’)
{
Start-Sleep -Seconds 1
$vm.ExtensionData.UpdateViewData(‘Runtime.PowerState’)
}
# Apply customization Spec to apply new network settings
Get-VM ‘BigServername’|
Set-VM -OSCustomizationSpec 'Windows Server 2012 R2' -Confirm:$false|
Start-VM
I can rebuild the template, or anything else we need to to make this work.
OR - is this just not the best way to configure VM's? If not, what about sysprep?
Good news, but first, I would really like to know where the log files are on which server for the OsCustomization process.
I decided to reverse engineer this and create a OSCS from within vCeneter and once I got that to work, I kept creating new OSCS via PowerCli until I could get that to work, creating a new VM. Once I got that to work, I tryied to apply that to a cloned vm, with no settings. I got that to work too. I tried to go back to my original image, but I couldn't get that to work. Something isn't right with that image. It tuns out that the problem was realted to permissions on the local guest.
New-OSCustomizationSpec -OrgName Company -OSType Windows -ChangeSid -Server 'vcenter.dom.com' -Name PowerCliOnly4 -FullName Administrator -Type Persistent -AdminPassword !password123 -TimeZone 'Eastern (U.S. and Canada)' -AutoLogonCount 3 -Domain dom -DomainUsername dadmin -DomainPassword !password123 -NamingScheme vm -Description "PowerCli Use only" -Confirm:$false
Get-OSCustomizationNicMapping -OSCustomizationSpec PowerCliOnly4 | Set-OSCustomizationNicMapping -Position 1 -IpMode UseStaticIP -IpAddress 10.10.10.98 -SubnetMask 255.255.255.0 -DefaultGateway 10.10.10.1 -Dns "10.10.10.10","10.10.10.11" -Confirm:$false
This seems to be very picky. Because the Domain is one of the parameters, you can't put it in the DomainUsername, no dom\dadmin. The part that I would really like to know how to over come is what if your vm has a different local administrator account than Administrator. It turns out that -FullName is not the account that it tires to log on localy with. When I created the OSCS from vCenter, I put "me" in the Name and Organization information and that is what was populated in the FullName property:
Name : PowerCliOnlyM
Type : Persistent
ServerId : /VIServer=dom\dadmin@vcenter.dom.com:443/
Server : vcenter.dom.com
LastUpdate : 9/24/2014 1:33:19 PM
DomainAdminUsername : dadmin NO dom/dadmin here!!!
DomainUsername : dadmin
Description : PowerCli use only, made manualy in vCenter.
AutoLogonCount : 3
ChangeSid : True
DeleteAccounts : False
DnsServer :
DnsSuffix :
Domain : vsi
FullName : Me
GuiRunOnce :
NamingPrefix :
NamingScheme : Vm
OrgName : CompanyTU
OSType : Windows
ProductKey :
TimeZone : Eastern (U.S. and Canada)
Workgroup :
LicenseMode : NotSpecified
LicenseMaxConnections :
EncryptionKey : {48, -126, 3, 108...}
ExtensionData : VMware.Vim.CustomizationSpecItem
Id : PowerCliOnlyM
Uid : /VIServer=vsi\diverso@atl01osi378.ads.vsi.com:443/OSCustomizationSpec=PowerCliOnlyM/
Client : VMware.VimAutomation.ViCore.Impl.V1.VimClient
AdminPassword : w
DomainAdminPassword : N
DomainPassword : N
Dns : {10.10.10.10, 10.10.10.11}
Wins :
SpecId : PowerCliOnlyM
Spec : PowerCliOnlyM
SpecType : Persistent
NetworkAdapterMac :
Position : 1
IPMode : UseStaticIP
IPAddress : 10.10.10.98
SubnetMask : 255.255.255.0
DefaultGateway : 10.10.10.1
AlternateGateway :
VCApplicationArgument :
Id : /VIServer=dom\dadmin@vcenter.dom.com:443/OSCustomizationNicMapping=OSCustomizationNicMappingImpl-PowerCliOnlyM-Persistent-1/
Uid : /VIServer=dom\dadmin@vcenter.dom.com:443/OSCustomizationNicMapping=OSCustomizationNicMappingImpl-PowerCliOnlyM-Persistent-1/
ExtensionData : VMware.Vim.CustomizationAdapterMapping
Client : VMware.VimAutomation.ViCore.Impl.V1.VimClient
Version : 1
I think it is good to know that the VM reboot 4 or 5 time as it goes through this process. It breaks is you try and do anything to the VM that interupt the process. I am sure I will think of more questions in a second.
Also, it seemd there were some problems with putting quotes, single or double around the password, but I did not double check this again, I just know that once I took them off, it started to work. I did run into other issues while testing like, I was using a single IP, so If I did not turn off on test VM, then the next one would not work because of the network conflct, maybe I should not admit that...lol
I'm not sure what you are trying to do with these lines ?
$Spec = Get-OSCustomizationSpec 'Windows Server 2012 R2'
$Spec += Get-OSCustomizationNicMapping -Spec $Spec
Are you trying to set the NIC configuration here ?
Chris has a nice post on this, see Dynamic VM Provisioning using PowerCLI and vSphere Customization Specifications
Did you get any error messages ?
Anything in the customisation (see folder C:\Windows\Temp/vmware-imc) and/or sysprep logs (see KB2001932) ?
For me PowerCLI 5.8 R1 does install a 32-bit and a 64-bit shortcut.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I want to do this one piece at a time to verfy that I have all the pieces and that there are no glaring issue with the choices that I make.
Following the article that you sent, I created this new OSC:
New-OSCustomizationSpec -FullName sTesta -OrgName CompanyName -OSType Windows -ChangeSid -Type Persistent -Name PowerCliOnly -AdminPassword password123 -TimeZone 'Eastern (U.S. and Canada)' -NamingScheme vm -Description "For use with PowerCli only" -Workgroup workgroup -Confirm:$false
Name : PowerCliOnly
Type : Persistent
ServerId : /VIServer=Dom\me@vcenter.dom.com:443/
Server : vcenter.dom.com
LastUpdate : 9/23/2014 5:53:54 PM
DomainAdminUsername :
DomainUsername :
Description : For use with PowerCli only
AutoLogonCount :
ChangeSid : True
DeleteAccounts : False
DnsServer :
DnsSuffix :
Domain :
FullName : sTesta
GuiRunOnce :
NamingPrefix :
NamingScheme : Vm
OrgName : CompanyName
OSType : Windows
ProductKey :
TimeZone : Eastern (U.S. and Canada)
Workgroup : workgroup
LicenseMode : NotSpecified
LicenseMaxConnections :
EncryptionKey : {48, -126, 3, 108...}
ExtensionData : VMware.Vim.CustomizationSpecItem
Id : PowerCliOnly
Uid : /VIServer=dom\me@vcenter.dom.com:443/OSCustomizationSpec=PowerCliOnly/
Client : VMware.VimAutomation.ViCore.Impl.V1.VimClient
AdminPassword : THere is one
DomainAdminPassword :
DomainPassword :
I don't know if it is relevent, but our server have a modified Administrator name, so we have to have the custome name to authenticate.
As I continue to think this through, I won't have a problem parameterizing this once I can get it to work, so I am going to use fixed setting this time until I can actualy see it make adjustment on the server and then I will worry about getting it to fulfill my needs.
Keeping that in mind, I made the New-OsCustomizationNicMapping (OSCNM):
New-OSCustomizationNicMapping -OSCustomizationSpec PowerCliOnly -IpMode UseStaticIP -IpAddress 10.10.10.10 -SubnetMask 255.255.255.0 -DefaultGateway 10.10.10.1 -Dns 10.10.10.100 -Confirm:$false
I hope that is everything we need to get something to apply to the server.
Those look correct. Did they work ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Nope. Here are the commands that I ran to set it:
$oscSpec = Get-OSCustomizationSpec -Name PowerCliONly
$vm = Get-VM -Name vmtest2
Set-VM -VM $vm -OSCustomizationSpec $oscSpec -Confirm:$false
$vm | Start-VM
$vm | Restart-VM -Confirm:$false
Get-VMGuest -VM $vm | select *
Open-VMConsoleWindow -VM $vm
OSFullName : Microsoft Windows Server 2012 (64-bit)
IPAddress : {169.254.213.253}
State : Running
Disks : {Capacity:64055406592, FreeSpace:53338750976, Path:C:\}
HostName : WIN-P9xxxxxR9RT
Nics : {Network adapter 1:proper vport group}
ScreenDimensions : {Width=1024, Height=768}
VmId : VirtualMachine-vm-107862
VM : vmtest2
VmUid : /VIServer=dom\me@vcenter.dom.com:443/VirtualMachine=VirtualMachine-vm-107862/
VmName : atl01test2
Uid : /VIServer=dom\me@vcenter.dom.com:443/VirtualMachine=VirtualMachine-vm-107862/VMGuest=/
GuestId : windows8Server64Guest
ToolsVersion : 9.0.11
ExtensionData : VMware.Vim.GuestInfo
Client : VMware.VimAutomation.ViCore.Impl.V1.VimClient
GuestFamily : windowsGuest
I really thought I had figured out the problem, when I noticed that the vmware tools were out of date, but I updated them and reran it and it did nothing. Also under the OCS I have -NamingScheme vm, is that right?
What am I missing?
I did not actualy build the template that I am using, so I just built a new template that I did almost nothing too except disable UAC. I created a new vm with the template and created a new OSCS for the server and applied it and again... nothing. I am not sure what the issue is, is there a way to verify if it is authenticating proplerly?
Are there any clues in the log files on the new VM (I mentioned the directory in my earlier answer) ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Not sure if this is what you mean?
Any thing in these?
Directory: C:\Windows\Temp\vmware-SYSTEM
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 9/14/2014 2:27 PM 4869 vmware-usbarb-25400.log
-a--- 9/23/2014 2:40 PM 5369 vmware-usbarb-2752.log
Good news, but first, I would really like to know where the log files are on which server for the OsCustomization process.
I decided to reverse engineer this and create a OSCS from within vCeneter and once I got that to work, I kept creating new OSCS via PowerCli until I could get that to work, creating a new VM. Once I got that to work, I tryied to apply that to a cloned vm, with no settings. I got that to work too. I tried to go back to my original image, but I couldn't get that to work. Something isn't right with that image. It tuns out that the problem was realted to permissions on the local guest.
New-OSCustomizationSpec -OrgName Company -OSType Windows -ChangeSid -Server 'vcenter.dom.com' -Name PowerCliOnly4 -FullName Administrator -Type Persistent -AdminPassword !password123 -TimeZone 'Eastern (U.S. and Canada)' -AutoLogonCount 3 -Domain dom -DomainUsername dadmin -DomainPassword !password123 -NamingScheme vm -Description "PowerCli Use only" -Confirm:$false
Get-OSCustomizationNicMapping -OSCustomizationSpec PowerCliOnly4 | Set-OSCustomizationNicMapping -Position 1 -IpMode UseStaticIP -IpAddress 10.10.10.98 -SubnetMask 255.255.255.0 -DefaultGateway 10.10.10.1 -Dns "10.10.10.10","10.10.10.11" -Confirm:$false
This seems to be very picky. Because the Domain is one of the parameters, you can't put it in the DomainUsername, no dom\dadmin. The part that I would really like to know how to over come is what if your vm has a different local administrator account than Administrator. It turns out that -FullName is not the account that it tires to log on localy with. When I created the OSCS from vCenter, I put "me" in the Name and Organization information and that is what was populated in the FullName property:
Name : PowerCliOnlyM
Type : Persistent
ServerId : /VIServer=dom\dadmin@vcenter.dom.com:443/
Server : vcenter.dom.com
LastUpdate : 9/24/2014 1:33:19 PM
DomainAdminUsername : dadmin NO dom/dadmin here!!!
DomainUsername : dadmin
Description : PowerCli use only, made manualy in vCenter.
AutoLogonCount : 3
ChangeSid : True
DeleteAccounts : False
DnsServer :
DnsSuffix :
Domain : vsi
FullName : Me
GuiRunOnce :
NamingPrefix :
NamingScheme : Vm
OrgName : CompanyTU
OSType : Windows
ProductKey :
TimeZone : Eastern (U.S. and Canada)
Workgroup :
LicenseMode : NotSpecified
LicenseMaxConnections :
EncryptionKey : {48, -126, 3, 108...}
ExtensionData : VMware.Vim.CustomizationSpecItem
Id : PowerCliOnlyM
Uid : /VIServer=vsi\diverso@atl01osi378.ads.vsi.com:443/OSCustomizationSpec=PowerCliOnlyM/
Client : VMware.VimAutomation.ViCore.Impl.V1.VimClient
AdminPassword : w
DomainAdminPassword : N
DomainPassword : N
Dns : {10.10.10.10, 10.10.10.11}
Wins :
SpecId : PowerCliOnlyM
Spec : PowerCliOnlyM
SpecType : Persistent
NetworkAdapterMac :
Position : 1
IPMode : UseStaticIP
IPAddress : 10.10.10.98
SubnetMask : 255.255.255.0
DefaultGateway : 10.10.10.1
AlternateGateway :
VCApplicationArgument :
Id : /VIServer=dom\dadmin@vcenter.dom.com:443/OSCustomizationNicMapping=OSCustomizationNicMappingImpl-PowerCliOnlyM-Persistent-1/
Uid : /VIServer=dom\dadmin@vcenter.dom.com:443/OSCustomizationNicMapping=OSCustomizationNicMappingImpl-PowerCliOnlyM-Persistent-1/
ExtensionData : VMware.Vim.CustomizationAdapterMapping
Client : VMware.VimAutomation.ViCore.Impl.V1.VimClient
Version : 1
I think it is good to know that the VM reboot 4 or 5 time as it goes through this process. It breaks is you try and do anything to the VM that interupt the process. I am sure I will think of more questions in a second.
Also, it seemd there were some problems with putting quotes, single or double around the password, but I did not double check this again, I just know that once I took them off, it started to work. I did run into other issues while testing like, I was using a single IP, so If I did not turn off on test VM, then the next one would not work because of the network conflct, maybe I should not admit that...lol
It was drivin me crazy that I could not user Get-Credential, so I did some further testing and it turns out that you can't user the domain name in the pop up box. Here is what worked:
$credOSC = Get-Credential -Credential dadmin
New-OSCustomizationSpec -OrgName TransUnion -OSType Windows -ChangeSid -Server 'vCenter.dom.com' -Name PowerCliOnly5 -FullName Administrator -Type Persistent -AdminPassword !password123 -TimeZone 'Eastern (U.S. and Canada)' -AutoLogonCount 3 -Domain vsi -DomainCredentials $credOSC -NamingScheme vm -Description "PowerCli Use only" -Confirm:$false
Get-OSCustomizationNicMapping -OSCustomizationSpec PowerCliOnly5 | Set-OSCustomizationNicMapping -Position 1 -IpMode UseStaticIP -IpAddress 10.10.10.98 -SubnetMask 255.255.255.0 -DefaultGateway 10.10.10.1 -Dns "10.10.10.10","10.10.10.11" -Confirm:$false
notice, you can't use ---- $credOSC = Get-Credential -Credential dom\dadmin
I have it sorted in this way:
( this is part of a longer script)
# Reading VMs to deploy and if they are windows asking to load credentials per Domain
Foreach ($VM in $newVMs) {
$Error.Clear()
If ($VM.OSType -eq "Windows") {
If ( !$credentials.ContainsKey($VM.domain)) {
$new_cred = Get-Credential
$credentials.Add($VM.domain,$new_cred)
}
}
}
If ($VM.OSType -eq "Windows") {
$credential = $credentials.Get_Item($VM.domain)
$fullname = $credential.UserName.Split('\')[1]
$orgname = $credential.UserName.Split('\')[0]
$tempSpec = New-OSCustomizationSpec -Name temp$vmName -NamingScheme fixed `
-NamingPrefix $VM.Name -Domain $VM.domain -FullName $fullname -OrgName $orgname `
-DomainCredentials $credential -TimeZone 085 -ChangeSid -OSType Windows
$tempSpec | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping `
-IpMode UseStaticIP -IpAddress $VM.IPAddress -SubnetMask $VM.SubnetMask `
-Dns $VM.pDNS,$VM.sDNS -DefaultGateway $VM.Gateway | Out-Null
I give this available at GITHUB