New-Datacenter
VMware: Creates a new datacenter
#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]$CenterName,
[string]$FolderName
)
Process {
$vmServer = $null
try {
$vmServer = Connect-VIServer -Server $VIServer -Credential $VICredential -ErrorAction Stop
$folder = Get-Folder -Server $vmServer -Name $FolderName -ErrorAction Stop
$null = New-Datacenter -Server $vmServer -Name $CenterName -Location $folder -Confirm:$false -ErrorAction Stop
$result = Get-Datacenter -Server $vmServer -Name $CenterName -ErrorAction Stop | Select-Object *
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
foreach ($item in $result) {
$item | Add-Member -NotePropertyName 'Timestamp' -NotePropertyValue $timestamp -Force
Write-Output $item
}
}
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
Name for the new datacenter
Location folder where the new datacenter will be created