Copy-OSCustomizationSpec
VMware: Copies an OS customization specification
#Requires -Version 5.1
#Requires -Modules VMware.VimAutomation.Core
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true)]
[string]$VIServer,
[Parameter(Mandatory = $true)]
[pscredential]$VICredential,
[Parameter(Mandatory = $true)]
[string]$SourceSpecificationId,
[Parameter(Mandatory = $true)]
[string]$SpecName,
[ValidateSet("Persistent", "NonPersistent")]
[string]$SpecificationType
)
Process {
try {
[string[]]$Properties = @('Name', 'Type', 'Server', 'LastUpdate', 'DomainAdminUsername', 'DomainUsername', 'Description', 'Domain', 'FullName', 'OSType', 'LicenseMode', 'LicenseMaxConnections', 'Id')
$vmServer = Connect-VIServer -Server $VIServer -Credential $VICredential -ErrorAction Stop
$cmdArgs = @{ ErrorAction = 'Stop'; Server = $vmServer }
$spec = Get-OSCustomizationSpec @cmdArgs -ID $SourceSpecificationId -ErrorAction Stop
$cmdArgs.Add('Confirm', $false)
$cmdArgs.Add('Name', $SpecName)
$cmdArgs.Add('OSCustomizationSpec', $spec)
if ($PSBoundParameters.ContainsKey('SpecificationType')) { $cmdArgs.Add('Type', $SpecificationType) }
$result = New-OSCustomizationSpec @cmdArgs | Select-Object $Properties
if ($null -ne $result) { $result | Add-Member -NotePropertyName Timestamp -NotePropertyValue (Get-Date -Format "yyyy-MM-dd HH:mm:ss") -PassThru -Force }
}
catch { throw }
finally { if ($null -ne $vmServer) { Disconnect-VIServer -Server $vmServer -Force -Confirm:$false -ErrorAction SilentlyContinue } }
}IP address or DNS name of the vSphere server
PSCredential object for authenticating with the server
ID of the source OS customization specification
Name of the new OS customization specification
Type: Persistent or NonPersistent