Powershell - Add rules



I made a start of script in powershell to allow me to industrialized the creation of new object, but I still have 2 points blocking

- I wish I could link the "New-AdcContentRule" that I created before with the "AdcSubVirtualService" that I created
- And I would like to put in the "AdcSubVirtualService" option "HTTP Header Modifications" to "RewriteRule"

here is the script

$lm49 = ConvertTo-SecureString "PASSWORD" -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential("bal", $lm49)
Initialize-LmConnectionParameters -Address AAA.BBB.CCC.DDD -LBPort ZZZ -Credential $creds -Verbose

$ContentMatchingRuleName    = "name_rule"
$ContentMatchingRulePattern = "/^\/URL.*/"

$VirtualServiceName         = "AAA.BBB.CCC.DDD"
$VirtualServicePort         = ZZZ
$CheckedPort                = 8180
$SubVSName                  = "SubVSName"
$Url                        = "/URL"
$AllowedVirtualHosts        = "URL"
$AllowedVirtualDirectories  = "/directory*"
$SchedulingMethod           = "fixed"
$HeaderModifications        = "Replace Header"
#$HTTPHeaderModifications     = ""

$LOADVS = Set-AdcVirtualService -VirtualService AAA.BBB.CCC.DDD -VSPort ZZZ -VSProtocol tcp
$LOADVSIndex = ($LOADVS.Data.VS.SubVS[-1]).VSIndex
$LOADSubVS = Get-AdcRealServer -VSIndex $LOADVSIndex
$LOADSubVSAddr0 = ($LOADSubVS.Data.Rs.Item(0)).Addr
$LOADSubVSWeight0 = ($LOADSubVS.Data.Rs.Item(0)).Weight
$LOADSubVSAddr1 = ($LOADSubVS.Data.Rs.Item(1)).Addr
$LOADSubVSWeight1 = ($LOADSubVS.Data.Rs.Item(1)).Weight
# Creation Rules & Checking > Content Rules
New-AdcContentRule -RuleName $ContentMatchingRuleName -MatchType regex -Pattern $ContentMatchingRulePattern -NoCase 1

# Create Sub Virtual Service
$NASVS = New-AdcSubVirtualService -VirtualService $VirtualServiceName -VSPort $VirtualServicePort -VSProtocol tcp
$NASVSIndex = ($NASVS.Data.VS.SubVS[-1]).VSIndex

Set-AdcSubVirtualService -SubVSIndex $NASVSIndex -CheckPort $CheckedPort -CheckType http -CheckUrl $Url -CheckUse1_1 0 -Nickname $SubVSName -VSType http -Weight 1000 -ESPEnabled $True -AllowedHosts $AllowedVirtualHosts -AllowedDirectories $AllowedVirtualDirectories -Schedule $SchedulingMethod -CheckUseGet 1 -AddVia 2 -StandByAddr AAA.BBB.CCC.DDD -StandByPort ZZZ
New-AdcRealServer -RealServer $LOADSubVSAddr1 -RealServerPort $CheckedPort -Enable $true -Forward nat -VSIndex $NASVSIndex -Weight $LOADSubVSWeight0
New-AdcRealServer -RealServer $LOADSubVSAddr0 -RealServerPort $CheckedPort -Enable $true -Forward nat -VSIndex $NASVSIndex -Weight $LOADSubVSWeight1