Sample/Config_Systems.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<#
Config_Systems.ps1
- Example scripts to illustrate how to deploy config pattern to target systems.
 
Lenovo Copyright
© Copyright Lenovo 2015. LIMITED AND RESTRICTED RIGHTS NOTICE: If data or software is delivered pursuant a General Services Administration “GSA” contract, use, reproduction, or disclosure is subject to restrictions set forth in Contract No. GS-35F-05925.
#>



# Define the variable value
$LxcaUserName = "USERID"
$LxcaPassword = ConvertTo-SecureString "Password" -AsPlainText –Force
$LxcaIP = "10.240.197.26"

# The pattern id, you can get it by cmdlet Get-LXCAConfigPattern
$patternId = 4
$referenceSystemUuid = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
$targetSystems = "226B3EA4DF7A11D493E6951515157171","FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"



# First connect to LXCA server
$Cred = New-Object System.Management.Automation.PSCredential($LxcaUserName, $LxcaPassword)
Connect-LXCA $LxcaIP -Credential $Cred -SkipCertificateCheck

if ($patternId -eq "")
{
    $profile = Get-LXCAConfigProfile | where {$_.ServerUuid -eq $referenceSystemUuid}
    if ($profile -ne $null)
    {
        $patternId = $profile[0].PatternId
    }
}

if ($patternId -eq "")
{
    Write-Error -Message "Pattern Id is empty (cannot retrieve pattern id from reference system)."
}
else
{
    Write-Host ("`nDeploy pattern {0} to target systems {1}." -f $patternId,([string]::Join(",",$targetSystems)))
    $ret = Install-LXCAConfigPattern -PatternId $patternId -TargetRackServerId $targetSystems -Restart Defer
    if ($ret -eq $null)
    {
        Write-Host "Install-LXCAConfigPattern is failed with unexcepted error!" -ForegroundColor Red
    }
    else
    {
        $ret | Format-Table -Property Uuid,Success
    }
}


# Disconnect from LXCA server
Disconnect-LXCA