Advertisement
vpenkoff

Untitled

Sep 20th, 2016
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Workflow Create-MagentoNetwork
  2. {
  3.     param
  4.      (
  5.         # Main Parameter
  6.         [Parameter(Mandatory=$true)]       
  7.         [string]$SubscriptionID,
  8.        
  9.         # Main Parameter
  10.         [Parameter(Mandatory=$true)]       
  11.         [string]$UserID,
  12.            
  13.         # Main Parameter
  14.         [Parameter(Mandatory=$true)]       
  15.         [string]$NetworkName
  16.      )
  17.    
  18.    
  19.     $Creds = Get-AutomationPSCredential -Name 'CredBobby'
  20.     $VMMServer = Get-AutomationVariable -Name 'VMMServer'
  21.     $SCVMMConnection = Get-AutomationConnection -Name 'SCVMM Connect'
  22.     $VmmServerName = $SCVMMConnection.ComputerName
  23.    
  24.     inlinescript {
  25.         try {
  26.             Import-Module virtualmachinemanager
  27.            
  28.             $subnetValue = "10.0.0.0/24"
  29.             $subnetName = "MagentoSubnet"
  30.             $dnsIP = "66.113.172.39"
  31.             $ipAdressPoolName = "MagentoIPPool"
  32.             $ipAddressRangeStart = "10.0.0.2"
  33.             $ipAddressRangeEnd = "10.0.0.254"
  34.             $vmNetworkName = $Using:NetworkName#"MagentoNetwork"
  35.            
  36.    
  37.             $VMMobject = Get-SCVMMServer -ComputerName $Using:VMMServer -ForOnBehalfOf| Out-Null
  38.            
  39.             $UserRole = Get-SCUserRole | Where-Object {$_.Name -match $Using:SubscriptionID}
  40.    
  41.             $CloudObj = Get-SCCloud -Name "Fabric"
  42.             $logicalNetwork = Get-SCLogicalNetwork -Cloud $CloudObj -Name "Provider Address Space"
  43.    
  44.             $vmNetwork = New-SCVMNetwork -Name $vmNetworkName -LogicalNetwork $logicalNetwork -OnBehalfOfUser $UserRole.Name -OnBehalfOfUserRole $UserRole -Owner $UserRole.Name
  45.                    
  46.             $subnet = New-SCSubnetVLan -Subnet $subnetValue
  47.             $vmSubnet = New-SCVMSubnet -Name $subnetName -VMNetwork $vmNetwork -SubnetVLan $subnet -OnBehalfOfUser $UserRole.Name -OnBehalfOfUserRole $UserRole
  48.    
  49.             $allDnsServer = @($dnsIP)
  50.    
  51.             $staticIPAddressPool = New-SCStaticIPAddressPool -Name $ipAdressPoolName `
  52.                 -VMSubnet $vmSubnet -Subnet $subnetValue -IPAddressRangeStart $ipAddressRangeStart `
  53.                 -IPAddressRangeEnd $ipAddressRangeEnd -DNSServer $allDnsServer `
  54.                 -RunAsynchronously -OnBehalfOfUser $UserRole.Name -OnBehalfOfUserRole $UserRole
  55.    
  56.             $gatewayDevice = Get-SCNetworkGateway -Name "CLRDWSG03"
  57.             $VmNetworkGateway = Add-SCVMNetworkGateway -Name "MagentoNetwork_Gateway" -EnableBGP $false -NetworkGateway $gatewayDevice -VMNetwork $vmNetwork
  58.             $externalIpPoolVar = Get-SCStaticIPAddressPool -Name "rdcloud-chi_Public01 Pool" #-ID "aa6e0e1e-7ed6-471d-9b50-d66e2096ef7e"
  59.             $natConnection = Add-SCNATConnection -Name "MagentoNetwork_NatConnection" -VMNetworkGateway $VmNetworkGateway -ExternalIPPool $externalIpPoolVar
  60.         } catch {
  61.             Throw "Exception: $_"
  62.         }
  63.     } -PSComputerName $VmmServerName -PSCredential $Creds
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement