Skip to content

Import-AutoDeployState

VMware: Restores the state of the Auto Deploy service

#Requires -Version 5.1
#Requires -Modules VMware.DeployAutomation

[CmdletBinding()]
Param(
    [Parameter(Mandatory = $true)]
    [string]$VIServer,
    [Parameter(Mandatory = $true)]
    [pscredential]$VICredential,
    [Parameter(Mandatory = $true)]
    [string]$ImportFilePath
)

Process {
    $vmServer = $null
    try {
        $vmServer = Connect-VIServer -Server $VIServer -Credential $VICredential -ErrorAction Stop
        $result = Import-AutoDeployState -Server $vmServer -ImportFilePath $ImportFilePath -ErrorAction Stop
        $output = [PSCustomObject]@{
            Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
            Status    = "Success"
            Result    = $result
        }
        Write-Output $output
    }
    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

File path of the restore file to import

An interactive directory of PowerShell scripts.