Public/VM.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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 |
# # Copyright 2021, Alexis La Goutte <alexis dot lagoutte at gmail dot com> # Copyright 2021, Cédric Moreau <moreaucedric0 at gmail dot com> # # SPDX-License-Identifier: Apache-2.0 # function Deploy-ArubaCPVm { <# .SYNOPSIS Deploy a ClearPass VM .DESCRIPTION Deploy a Virtual Machine ClearPass on a vSphere environment with a lot of parameters like the choice of the cluster, the datastore, and the host. You can even preconfigure your VM with the network configuration, the hostname, and the dns. .EXAMPLE Deploy-ArubaCPVm -ovf_path "D:\ISO\CPPM-VM-x86_64-6.9.0.130064-ESX\CPPM-VM-x86_64-6.9.0.130064-ESX.ovf" -vm_Host "host_PowerarubaCP-01" -datastore "datastore_powerarubacp-01" -cluster "cluster_powerarubacp-01" -name_vm "CPPM" -vmnetwork1 "CPPM - MGMT" -vmnetwork2 "CPPM - DATA" This install your .ovf on your vsphere with the host, the datastore, the cluster, the folder to place it and the name of your vm. It also configure your vm with a hostname, a network configuration, the network adapter and the port group of your vSwitch .EXAMPLE $cppmBuildParams = @{ ovf_path = "D:\ISO\CPPM-VM-x86_64-6.9.0.130064-ESX\CPPM-VM-x86_64-6.9.0.130064-ESX.ovf" vm_host = "host_PowerarubaCP-01" datastore = "datastore_powerarubacp-01" cluster = "cluster_powerarubacp-01" inventory = "PowerArubaCP" name_vm = "CPPM" capacityGB = "80" #Minimum size for LAB memoryGB = "8" #Default value cpu = "8" #Default value StartVM = $true vmnetwork1 = "CPPM - MGMT" vmnetwork2 = "CPPM - DATA" } # end $cppmBuildParams PS>Deploy-ArubaCPVm @cppmBuildParams Deploy Aruba ClearPass VM by pass array with settings. #> Param( [Parameter (Mandatory = $true, Position = 1)] [string]$ovf_path, [Parameter (Mandatory = $true, Position = 2)] [string]$vm_host, [Parameter (Mandatory = $true)] [string]$datastore, [Parameter (Mandatory = $true)] [string]$cluster, [Parameter (Mandatory = $false)] [string]$inventory, [Parameter (Mandatory = $true)] [string]$name_vm, [Parameter (Mandatory = $false)] [ValidateRange(31, 512)] [int]$capacityGB = 80, [Parameter (Mandatory = $false)] [ValidateRange(2, 32)] [int]$memoryGB, [Parameter (Mandatory = $false)] [ValidateRange(2, 32)] [int]$cpu, [Parameter(Mandatory = $false)] [switch]$StartVM = $false, [Parameter (Mandatory = $true)] [string]$vmnetwork1, [Parameter (Mandatory = $false)] [string]$vmnetwork2 ) Begin { } Process { #Check if VMWare PowerCLI is available (not use #Require because not mandatory module) if ($null -eq (Get-InstalledModule -name VMware.VimAutomation.Common -ErrorAction SilentlyContinue)) { Throw "You need to install VMware.PowerCLI (Install-Module VMware.PowerCLI)" } #Write-Warning "You need to have a vSwitch configured on your vSphere environment even if you use a DVS" #default vapp_config $vapp_config = @{ "source" = $ovf_path "name" = $name_vm } if ($DefaultVIServers.Count -eq 0) { throw "Need to be connect to vCenter (use Connect-VIServer)" } if (Get-VM $name_vm -ErrorAction "silentlyContinue") { Throw "VM $name_vm already exist, change name or remove VM" } if (-not (Get-Cluster -Name $cluster -ErrorAction "silentlycontinue")) { Throw "Cluster not found : $cluster" } else { $vapp_config.add("Location", $cluster) } if (-not (Get-VMHost -Name $vm_host -ErrorAction "silentlycontinue")) { Throw "Vm_Host not found : $vm_host" } else { $vapp_config.add("vmhost", $vm_host) } if (-not (Get-Datastore -Name $datastore -ErrorAction "silentlycontinue")) { Throw "Datastore not found : $datastore" } else { $vapp_config.add("datastore", $datastore) } if ( $PsBoundParameters.ContainsKey('inventory') ) { if (-not (Get-Inventory -Name $inventory -ErrorAction "silentlycontinue")) { Throw "Inventory not found : $inventory" } else { $vapp_config.add("inventory", $inventory) } } $ovfConfig = Get-OvfConfiguration -Ovf $ovf_path #Check if vSwitch is available ? $ovfConfig.NetworkMapping.VM_Network.Value = $vmnetwork1 if ( $PsBoundParameters.ContainsKey('vmnetwork2') ) { $ovfConfig.NetworkMapping.VM_Network_2.Value = $vmnetwork2 } Import-VApp @vapp_config -OvfConfiguration $ovfConfig | Out-Null #Add new disk (mininum 80GB ) New-HardDisk -VM $name_vm -CapacityGB $capacityGB -Persistence persistent | Out-Null #Change memory (8 by default) if ( $PsBoundParameters.ContainsKey('MemoryGB') ) { Get-VM $name_vm | Set-VM -MemoryGB $MemoryGB -confirm:$false | Out-Null } #Change CPU (8 by default) if ( $PsBoundParameters.ContainsKey('CPU') ) { Get-VM $name_vm | Set-VM -NumCPU $cpu -confirm:$false | Out-Null } #Set NetworkAdapter to enable (for both/All...) Get-VM $name_vm | Get-NetworkAdapter | Set-NetworkAdapter -StartConnected $true -Confirm:$false | Out-Null if ( $StartVM ) { Get-VM $name_vm | Start-VM | Out-Null Write-Output "$name_vm is started and ready to use" } else { Write-Output "$name_vm is ready to use (need to Start VM !)" } } End { } } function Set-ArubaCPVmFirstBoot { <# .SYNOPSIS Configure the first boot of Clearpass VM .DESCRIPTION Configure the first boot (Appliance Type and encrypt disk) of ClearPass VM .EXAMPLE $cppmFirstBootParams = @{ version = "6.9" name_vm = "PowerArubaCP-CPPM" appliance_type = "CLABV" } PS>Set-ArubaCPVmFirstBoot @cppmFirstBootParams Configuration of first CPPM Boot (VM Name and Appliance Type CLABV ) .EXAMPLE Set-ArubaCPVmFirstBoot -version 6.9 -name_vm PowerArubaCP-CPPM -appliance_type C3000V -encrypt_disk:$false Configuration of first CPPM Boot (VM Name, Appliance Type C3000V and encrypt disk disable ) #> [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")] Param( [Parameter (Mandatory = $true)] [ValidateSet("6.8", "6.9", "6.10", "6.11")] [version]$version, [Parameter (Mandatory = $true)] [ValidateSet("CLABV", "C1000V", "C2000V", "C3000V")] [string]$appliance_type, [Parameter (Mandatory = $true)] [string]$name_vm, [Parameter (Mandatory = $false)] [switch]$encrypt_disk ) Begin { } Process { if (-not (Get-Command -name Set-VMKeystrokes -ErrorAction SilentlyContinue)) { Throw "You need to install/import Set-VMKeystrokes script (Install-Script -Name VMKeystrokes)" } #TODO Check the VM is available switch ( $appliance_type ) { "CLABV" { $StringInput = "1" } "C1000V" { $StringInput = "2" } "C2000V" { $StringInput = "3" } "C3000V" { $StringInput = "4" } } Write-Output "Configure Appliance type: $appliance_type" Set-VMKeystrokes -VMName $name_vm -StringInput $StringInput -ReturnCarriage $true 6>> $null #With version 6.8 (and before), there is a disk perf check if ($version -eq "6.8") { Start-Sleep 20 } #Use secondary disk Set-VMKeystrokes -VMName $name_vm -StringInput y 6>> $null #Encrypt all local data if ( $PsBoundParameters.ContainsKey('encrypt_disk') ) { if ( $encrypt_disk ) { $StringInput = "y" } else { $StringInput = "n" } } else { #By Default Encrypt Local data $StringInput = "y" } Write-Output "Configure Encrypt disk: $encrypt_disk" Set-VMKeystrokes -VMName $name_vm -StringInput $StringInput 6>> $null Write-Output "First Configuration boot is finish, CPPM copy now data and reboot, it will be available on 10/15 minutes for setup" #Copy now data and reboot, need to wait 10/15 minutes... } End { } } function Set-ArubaCPVmSetup { <# .SYNOPSIS Setup a VM ClearPass .DESCRIPTION Setup a VM ClearPass (hostname, management/data ip address, dns, password...). .EXAMPLE Set-ArubaCPVmSetup -name "CPPM" -version 6.9 -hostname "CPPM" -mgmt_ip 192.0.2.225 -mgmt_netmask 24 -mgmt_gateway 192.0.2.254 -dns_primary 192.0.2.1 -new_pasword "MyPassword" Initial configuration with minimal settings of ClearPasss (Name, IP Address MGMT, DNS, Password...) .EXAMPLE $cppmsetupParams = @{ name_vm = "CPPM" version = "6.9" hostname = "CPPM" mgmt_ip = "192.0.2.225" mgmt_netmask = "24" mgmt_gateway = "192.0.2.254" data_ip = "198.0.51.225" data_netmask = "24" data_gateway = "198.0.51.254" dns_primary = "192.0.2.1" dns_secondary = "198.0.51.200" new_password = "MyPassword" ntp_primary = "192.0.2.1" ntp_secondary = "198.0.51.200" timezone_continent = "8" timezone_country = "14" } PS>Set-ArubaCPVmSetup @cppmsetupParams Initial configuration of ClearPasss (Name, IP Address MGMT/Data, DNS, Password, NTP, Timezone...) for Timezone, on this example, it is for Europe/France(Paris) #> [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")] Param( [string]$name_vm, [Parameter (Mandatory = $true)] [ValidateSet("6.8", "6.9", "6.10", "6.11")] [version]$version, [Parameter (Mandatory = $true)] [string]$hostname, [Parameter (Mandatory = $true)] [ipaddress]$mgmt_ip, [Parameter (Mandatory = $true)] [ValidateRange(0, 32)] [int]$mgmt_netmask, [Parameter (Mandatory = $true)] [ipaddress]$mgmt_gateway, [Parameter (Mandatory = $false)] [ipaddress]$data_ip, [ValidateRange(0, 32)] [int]$data_netmask, [Parameter (Mandatory = $false)] [ipaddress]$data_gateway, [Parameter (Mandatory = $true)] [ipaddress]$dns_primary, [Parameter (Mandatory = $false)] [ipaddress]$dns_secondary, [Parameter (Mandatory = $true)] [string]$new_password, [Parameter (Mandatory = $false)] [ValidateRange(1, 10)] [int]$timezone_continent, [Parameter (Mandatory = $false)] [ValidateRange(1, 55)] [int]$timezone_country, [Parameter (Mandatory = $false)] [ipaddress]$ntp_primary, [Parameter (Mandatory = $false)] [ipaddress]$ntp_secondary, [Parameter (Mandatory = $false)] [switch]$fips ) Begin { } Process { if ($timezone_continent -xor $timezone_country) { Throw "You need to specific Timezone Continent and Country on the sametime" } if (($data_ip -xor $data_netmask) -or ($data_netmask -xor $data_gateway)) { Throw "You need to specific Data IP, netmask and Gateway on the sametime" } if (-not (Get-Command -name Set-VMKeystrokes -ErrorAction SilentlyContinue)) { Throw "You need to install/import Set-VMKeystrokes script (Install-Script -Name VMKeystrokes)" } #Connection Write-Output "Connection to console using default login/password" Set-VMKeystrokes -VMName $name_vm -StringInput appadmin -ReturnCarriage $true 6>> $null Start-Sleep 1 Set-VMKeystrokes -VMName $name_vm -StringInput eTIPS123 -ReturnCarriage $true 6>> $null Start-Sleep 15 #Initial Setup #Hostname Write-Output "Configure hostname: $hostname" Set-VMKeystrokes -VMName $name_vm -StringInput $hostname -ReturnCarriage $true 6>> $null Start-Sleep 1 #Management IPv4 if ($version -eq "6.8") { Write-Output "Configure Management IPv4: $mgmt_ip / $mgmt_netmask" Set-VMKeystrokes -VMName $name_vm -StringInput $mgmt_ip.ToString() -ReturnCarriage $true 6>> $null Start-Sleep 1 #Netmask Set-VMKeystrokes -VMName $name_vm -StringInput (Convert-ArubaCPCIDR2Mask($mgmt_netmask)) -ReturnCarriage $true 6>> $null Start-Sleep 1 #Gateway (Management) Write-Output "Configure Management IPv4 Gateway: $mgmt_gateway" Set-VMKeystrokes -VMName $name_vm -StringInput $mgmt_gateway.ToString() -ReturnCarriage $true 6>> $null Start-Sleep 1 } else { #with 6.9.x using CIDR for netmask and add IPv6 support $mgmt = $mgmt_ip.ToString() + "/" + $mgmt_netmask Write-Output "Configure Management IPv4: $mgmt_ip / $mgmt_netmask" Set-VMKeystrokes -VMName $name_vm -StringInput $mgmt -ReturnCarriage $true 6>> $null Start-Sleep 1 Write-Output "Configure Management IPv4 Gateway: $mgmt_gateway" Set-VMKeystrokes -VMName $name_vm -StringInput $mgmt_gateway.ToString() -ReturnCarriage $true 6>> $null Start-Sleep 1 #Management IPv6 (Skip...) Write-Output "Skip Configure Management IPv6..." Set-VMKeystrokes -VMName $name_vm -SpecialKeyInput "KeyEnter" 6>> $null Start-Sleep 1 } #Data Port if ($version -eq "6.8") { if ($data_ip -and $data_netmask -and $data_gateway) { $data = $data_ip.ToString() + "/" + $data_netmask Write-Output "Configure Data IPv4: $data_ip / $data_netmask" Set-VMKeystrokes -VMName $name_vm -StringInput $data_ip.ToString() -ReturnCarriage $true 6>> $null Start-Sleep 1 #Netmask Set-VMKeystrokes -VMName $name_vm -StringInput (Convert-ArubaCPCIDR2Mask($data_netmask)) -ReturnCarriage $true 6>> $null Start-Sleep 1 #Gateway (Data) Write-Output "Configure Data IPv4 Gateway: $data_gateway" Set-VMKeystrokes -VMName $name_vm -StringInput $data_gateway.ToString() -ReturnCarriage $true 6>> $null Start-Sleep 1 } else { Write-Output "Skip Configure Data IPv4" Set-VMKeystrokes -VMName $name_vm -SpecialKeyInput "KeyEnter" 6>> $null Start-Sleep 1 } } else { #with 6.9.x using CIDR for netmask and add IPv6 support if ($data_ip -and $data_netmask -and $data_gateway) { $data = $data_ip.ToString() + "/" + $data_netmask Write-Output "Configure Data IPv4: $data_ip / $data_netmask" Set-VMKeystrokes -VMName $name_vm -StringInput $data -ReturnCarriage $true 6>> $null Start-Sleep 1 Write-Output "Configure Data IPv4 Gateway: $data_gateway" Set-VMKeystrokes -VMName $name_vm -StringInput $data_gateway.ToString() -ReturnCarriage $true 6>> $null Start-Sleep 1 #IPv6 Write-Output "Skip Configure Data IPv6..." Set-VMKeystrokes -VMName $name_vm -SpecialKeyInput "KeyEnter" 6>> $null Start-Sleep 1 } else { Write-Output "Skip Configure Data IPv4" Set-VMKeystrokes -VMName $name_vm -SpecialKeyInput "KeyEnter" 6>> $null Start-Sleep 1 #IPv6 Write-Output "Skip Configure Data IPv6" Set-VMKeystrokes -VMName $name_vm -SpecialKeyInput "KeyEnter" 6>> $null Start-Sleep 1 } } #DNS Write-Output "Configure DNS Primary: $dns_primary" Set-VMKeystrokes -VMName $name_vm -StringInput $dns_primary -ReturnCarriage $true 6>> $null Start-Sleep 1 Write-Output "Configure DNS Secondary: $dns_secondary" Set-VMKeystrokes -VMName $name_vm -StringInput $dns_secondary -ReturnCarriage $true 6>> $null Start-Sleep 1 #SLAAC if ($version -ge "6.10") { Write-Output "Skip Configure SLAAC IPv6" Set-VMKeystrokes -VMName $name_vm -SpecialKeyInput "KeyEnter" 6>> $null Start-Sleep 1 } #Password Write-Output "Configure Password..." Set-VMKeystrokes -VMName $name_vm -StringInput $new_password -ReturnCarriage $true 6>> $null Start-Sleep 1 Set-VMKeystrokes -VMName $name_vm -StringInput $new_password -ReturnCarriage $true 6>> $null Start-Sleep 1 #NTP if ($timezone_continent -or $ntp_primary) { Set-VMKeystrokes -VMName $name_vm -StringInput y -ReturnCarriage $true 6>> $null Start-Sleep 1 if ($ntp_primary) { #Configure NTP Server Set-VMKeystrokes -VMName $name_vm -StringInput 2 -ReturnCarriage $true 6>> $null Start-Sleep 1 Write-Output "Configure NTP Primary: $ntp_primary" Set-VMKeystrokes -VMName $name_vm -StringInput $ntp_primary -ReturnCarriage $true 6>> $null Start-Sleep 1 Write-Output "Configure NTP Secondary: $ntp_secondary" Set-VMKeystrokes -VMName $name_vm -StringInput $ntp_secondary -ReturnCarriage $true 6>> $null Start-Sleep 1 } else { #Skip Configure Data and time Write-Output "Skip Configure NTP ..." Set-VMKeystrokes -VMName $name_vm -StringInput 1 -ReturnCarriage $true 6>> $null Start-Sleep 1 Set-VMKeystrokes -VMName $name_vm -SpecialKeyInput "KeyEnter" 6>> $null Start-Sleep 1 Set-VMKeystrokes -VMName $name_vm -SpecialKeyInput "KeyEnter" 6>> $null Start-Sleep 1 } if ($timezone_continent) { Write-Output "Configure Timezone (Continent and Country)" #Configure timezone (Continent and Country) Set-VMKeystrokes -VMName $name_vm -StringInput y -ReturnCarriage $true 6>> $null Start-Sleep 1 Set-VMKeystrokes -VMName $name_vm -StringInput $timezone_continent -ReturnCarriage $true 6>> $null Start-Sleep 1 Set-VMKeystrokes -VMName $name_vm -StringInput $timezone_country -ReturnCarriage $true 6>> $null Start-Sleep 1 Set-VMKeystrokes -VMName $name_vm -StringInput 1 -ReturnCarriage $true 6>> $null Start-Sleep 1 } else { #Skip timezone (Continent and Country) Write-Output "Skip Configure Timezone (Continent and Country) ..." Set-VMKeystrokes -VMName $name_vm -StringInput n -ReturnCarriage $true 6>> $null Start-Sleep 1 if ($version -ne "6.8") { #No need to confirm (1) Time Settings before 6.9 Set-VMKeystrokes -VMName $name_vm -StringInput 1 -ReturnCarriage $true 6>> $null Start-Sleep 1 } } } else { #No NTP or Timezone settings, skip Write-Output "Skip Configure NTP and Timezone (Continent and Country) ..." Set-VMKeystrokes -VMName $name_vm -StringInput n -ReturnCarriage $true 6>> $null Start-Sleep 1 } #FIPS Write-Output "Configure FIPS $fips" if ( $PsBoundParameters.ContainsKey('fips') ) { if ( $fips ) { $StringInput = "y" } else { $StringInput = "n" } } else { #By Default FIPS is disable.. $StringInput = "n" } Set-VMKeystrokes -VMName $name_vm -StringInput $StringInput -ReturnCarriage $true 6>> $null Start-Sleep 1 #Configuration OK ? Set-VMKeystrokes -VMName $name_vm -StringInput y -ReturnCarriage $true 6>> $null Write-Output "Setup is finish, now CPPM will be configure and restart service (need to wait 7/8 minutes before try to connect)" } End { } } function Set-ArubaCPVmAddLicencePlatform { <# .SYNOPSIS Configure Plaform Licence on VM ClearPass .DESCRIPTION Configure Plaform Licence Key on VM ClearPass .EXAMPLE $cppmLicenceKeyParams = @{ mgmt_ip = "10.200.11.225" licencekey = "---BEGIN....." } PS>Set-ArubaCPVmAddLicencePlatform @cppmLicenceKeyParams Configure initial Platform Licence key on ClearPass #> [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")] Param( [Parameter (Mandatory = $true)] [ipaddress]$mgmt_ip, [Parameter (Mandatory = $true)] [string]$licencekey ) Begin { } Process { $uri = "https://" + $mgmt_ip + "/tips/addLicense.action" $body = @{ appId = 101 ; agree_eula = "on"; licenseKey = $licencekey } #Token ? (for > 6.11) $iwr = Invoke-WebRequest $uri -Method "GET" -SkipCertificateCheck -SessionVariable LicenceCPPM $token = ($iwr.InputFields | Where-Object {$_.name -eq "token"}).value if ($token) { $body.add("struts.token.name","token") $body.add("token", $token) } $uri = "https://" + $mgmt_ip + "/tips/submitLicense.action" Write-Verbose ($body | ConvertTo-Json) #No API available for this... push directly the licence with agreement eula Invoke-WebRequest $uri -Method "POST" -ContentType "application/x-www-form-urlencoded" -Body $body -WebSession $licenceCPPM -SkipCertificateCheck | Out-Null } End { } } function Set-ArubaCPVmApiClient { <# .SYNOPSIS Configure an API Client (Oauth) .DESCRIPTION Configure an API Client (Oauth) using console .EXAMPLE $cppmapiclientParams = @{ name_vm = "CPPM" new_password = "MyPassword" client_id = "PowerArubaCP" client_secret = "MySecret" } PS>Set-ArubaCPVmApiClient @cppmapiclientParams Configure an API Client (Oauth) with client_id and client_secret #> [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")] Param( [Parameter (Mandatory = $true)] [string]$name_vm, [Parameter (Mandatory = $true)] [string]$new_password, [Parameter (Mandatory = $true)] [string]$client_id, [Parameter (Mandatory = $true)] [string]$client_secret ) Begin { } Process { if (-not (Get-Command -name Set-VMKeystrokes -ErrorAction SilentlyContinue)) { Throw "You need to install/import Set-VMKeystrokes script (Install-Script -Name VMKeystrokes)" } #Connection to CPPM (using console) Write-Output "Connection to console using login/password" Set-VMKeystrokes -VMName $name_vm -StringInput appadmin -ReturnCarriage $true 6>> $null Start-Sleep 1 Set-VMKeystrokes -VMName $name_vm -StringInput $new_password -ReturnCarriage $true 6>> $null Start-Sleep 1 #Create API Client (oauth) Write-Output "Add API client $client_id" Set-VMKeystrokes -VMName $name_vm -StringInput "system create-api-client $client_id $client_secret" -ReturnCarriage $true 6>> $null Start-Sleep 1 #Exit ! Write-Output "Exit to console" Set-VMKeystrokes -VMName $name_vm -StringInput exit -ReturnCarriage $true 6>> $null } End { } } function Set-ArubaCPVmUpdate { <# .SYNOPSIS Update CPPM VM .DESCRIPTION Update CPPM VM (via copy file with SSH or HTTP(S)) using console Need to wait the time of copy file (> 1,2Giga) and update (10 to 15minutes) and launch restart of CPPM .EXAMPLE $cppmUpdateParams = @{ name_vm = "CPPM" new_password = "MyPassword" update_link = "http://192.0.2.1/CPPM-x86_64-20201119-clearpass-6.9-updates-5-aruba-69-patch.signed.tar" } PS>Set-ArubaCPVmUpdate @cppmUpdateParams Update CPPM to 6.9.5 using HTTP .EXAMPLE $cppmUpdateParams = @{ name_vm = "CPPM" new_password = "MyPassword" update_link = "powerarubacp@192.0.2.1:CPPM-x86_64-20201119-clearpass-6.9-updates-5-aruba-69-patch.signed.tar" ssh_password = "MySSH Password" } PS>Set-ArubaCPVmUpdate @cppmUpdateParams Update CPPM to 6.9.5 using SSH #> [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")] Param( [Parameter (Mandatory = $true)] [string]$name_vm, [Parameter (Mandatory = $true)] [string]$new_password, [Parameter (Mandatory = $true)] [string]$update_link, [Parameter (Mandatory = $false)] [string]$ssh_password ) Begin { } Process { if (-not (Get-Command -name Set-VMKeystrokes -ErrorAction SilentlyContinue)) { Throw "You need to install/import Set-VMKeystrokes script (Install-Script -Name VMKeystrokes)" } #Connection to CPPM (using console) Write-Output "Connection to console using login/password" Set-VMKeystrokes -VMName $name_vm -StringInput appadmin -ReturnCarriage $true 6>> $null Start-Sleep 1 Set-VMKeystrokes -VMName $name_vm -StringInput $new_password -ReturnCarriage $true 6>> $null Start-Sleep 1 #Update CPPM Write-Output "Update CPPM with $update_link" Set-VMKeystrokes -VMName $name_vm -StringInput "system update -i $update_link" -ReturnCarriage $true 6>> $null Start-Sleep 1 #if using SSH, need to specify the SSH password if ($ssh_password) { #if it is the first ssh connection to this ssh server, need to valid the key fingerprint Set-VMKeystrokes -VMName $name_vm -StringInput "yes" -ReturnCarriage $true 6>> $null Start-Sleep 3 #SSH Password Write-Output "Set SSH Password" Set-VMKeystrokes -VMName $name_vm -StringInput $ssh_password -ReturnCarriage $true 6>> $null Start-Sleep 1 } } End { } } |