Forum Discussion

Jeffrey_Silver1's avatar
Jeffrey_Silver1
Icon for Nimbostratus rankNimbostratus
Feb 26, 2014

iRule content show up in one line

When I create an iRule from a powershell script that includes HTTP content, the irule gets created, however, the HTTP is not delimited in the rule when you look at. Its all on one line. Is there any way to get the html to show up properly.

 

5 Replies

  • Could you please provide some sample PS code? Adding `n to a string in PS would cause it to use a new line but I'm not sure if that's what you want?

     

  • Patrik, the issue seems to be that even if you put the proper newline characters in the actual text, when you assign that text to the object the newline or carriage returns are not recognized. The irule in the code below gets created but when you go into the web interface and view the irule, all of the content is on a single line.

     

            $data = Get-Content $invar1
            $RuleDefinition = New-Object -TypeName iControl.LocalLBRuleRuleDefinition
            $RuleDefinition.rule_name = $rule
            **$RuleDefinition.rule_definition = $data**
            $ic.LocalLBRule.create( (,$RuleDefinition) )
  • After a few attempts I finally understood your dilemma. When reading from a file you get a System.Object array.

     

    Converting this to a string removes the line breaks.

     

    Try this:

     

    $def = (Get-Content iRuleContent.txt) -join "`n"

     

    $RuleDefinition = New-Object -TypeName iControl.LocalLBRuleRuleDefinition $RuleDefinition.rule_name = "iRulewithlines" $RuleDefinition.rule_definition = $def $f5.LocalLBRule.create($RuleDefinition )

     

  • Patrik, thanks for you help. You got me pointed in the right direction. What I had to do was to read the HTML file in line by line, and append those lines to an array followed by the [char]13. With the array filled, I used the array name as input to the rule_definition string. Works like a charm.

     

    • Patrik_Jonsson's avatar
      Patrik_Jonsson
      Icon for MVP rankMVP
      Actually you don't need to add [char]13. Seems like the commandlet takes care of that for you as long as you give it a proper string.