Created
November 22, 2013 16:50
-
-
Save Mierdin/7603106 to your computer and use it in GitHub Desktop.
This script is largely written by Alan Renouf - I put this here for my own reference because I made some modifications. Please visit his site at:
http://www.virtu-al.net/2011/09/30/automated-install-of-vshield-services/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add-PSSnapin VMware* | |
Function Connect-vShieldServer { | |
<# | |
.SYNOPSIS | |
Connects to a vShield Manager Server. | |
.DESCRIPTION | |
Connects to a vShield Manager Server. The cmdlet starts a new session with a vShield Manager Server using the specified parameters. | |
.PARAMETER Server | |
Specify the IP address or the DNS name of the vSphere server to which you want to connect. | |
.PARAMETER Username | |
Specify the user name you want to use for authenticating with the server. | |
.PARAMETER Password | |
Specifies the password you want to use for authenticating with the server. | |
.EXAMPLE | |
PS C:\> Connect-vShieldServer -server "192.168.0.88" -username "admin" -password "default" | |
Credit to Alan Renouf | |
http://www.virtu-al.net/2011/09/30/automated-install-of-vshield-services/ | |
#> | |
[CmdletBinding()] | |
Param ( | |
[Parameter(ValueFromPipeline=$true)] | |
$Server, | |
$Username, | |
$Password | |
) | |
process { | |
$httpClient = [System.Net.WebRequest]::Create("https://$server/api/2.0/app/firewall/protocols") | |
# Add Authorization headers | |
$authbytes = [System.Text.Encoding]::ASCII.GetBytes($username + ":" + $password) | |
$base64 = [System.Convert]::ToBase64String($authbytes) | |
$authorization = "Authorization: Basic " + $base64 | |
$httpClient.Headers.Add($authorization) | |
# Set Method | |
$httpClient.Method = "GET" | |
$response = $httpClient.GetResponse() | |
If ($response.StatusCode -eq "OK") { | |
$Global:DefaultvShieldServer = New-Object -TypeName PSObject -Property @{ | |
Name = $Server | |
ServerUri = "https://$server/" | |
Authorization = $authorization | |
} | |
Write-Host -ForegroundColor Yellow "Connected Succesfully to $Server" | |
} Else { | |
Write-Host -ForegroundColor Red "Unable to connect to $Server, debug info:" | |
$response | |
} | |
} | |
} | |
Function Get-NetworkID ($Datacenter) { | |
$datacenterView = ($Datacenter | Get-View) | |
$datacenterView.Network | Foreach { | |
$Network = New-Object -TypeName PSObject -Property @{ | |
Name = (Get-View –Id $_).name | |
ID = $_.Value | |
} | |
$Network | |
} | |
} | |
Function Post-vShieldAPI ($URL, $Body) { | |
$wc = New-Object System.Net.WebClient | |
# Add Authorization headers | |
$URL = ($Global:DefaultvShieldServer.ServerUri) + $URL | |
$wc.Headers.Add(($Global:DefaultvShieldServer.Authorization)) | |
$wc.UploadString($URL, "POST", $Body) | |
} | |
Function Install-vShieldApp ($VMHost, $Datastore, $ManagementPortGroup, $ManagementIP, $ManagementNetMask, $ManagementDGW) { | |
$VMHostMR = ($VMHost.Id).trim("HostSystem-") | |
$DatastoreMR = ($Datastore.Id).trim("Datastore-") | |
$NetworkMR = (Get-NetworkID -Datacenter (Get-Datacenter) | Where { $_.Name -eq $ManagementPortGroup}).ID | |
$Body = @" | |
<VshieldConfiguration> | |
<VszInstallParams> | |
<DatastoreId>$DatastoreMR</DatastoreId> | |
<ManagementPortSwitchId>$NetworkMR</ManagementPortSwitchId> | |
<MgmtInterface> | |
<IpAddress>$ManagementIP</IpAddress> | |
<NetworkMask>$ManagementNetMask</NetworkMask> | |
<DefaultGw>$ManagementDGW</DefaultGw> | |
</MgmtInterface> | |
</VszInstallParams> | |
<EpsecInstallParams>true</EpsecInstallParams> | |
<InstallAction>install</InstallAction> | |
</VshieldConfiguration> | |
"@ | |
Post-vShieldAPI -URL "api/1.0/vshield/$VMHostMR" -Body $Body | |
} | |
Connect-vShieldServer -Server 192.168.0.10 -username admin -password default | |
Connect-VIServer -Server 192.168.0.11 -user "admin" -password "password" | |
$i = 130 | |
Get-VMHost -Location CLUSTER01 | foreach { | |
#26-36 | |
$Datastore = Get-Datastore "DS01" | |
$PortGroup = Get-VirtualPortgroup -VMHost $_ -Name "VMWare Management" | |
$iStr = $i.ToString() | |
Install-vShieldApp -VMHost $_ ` | |
-Datastore $Datastore ` | |
-ManagementPortGroup $PortGroup ` | |
-ManagementIP "192.168.0.$iStr" ` | |
-ManagementDGW "192.168.0.1" ` | |
-ManagementNetMask "255.255.255.0" | |
$i++ | |
Write-Host "Installed on $iStr" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment