none
Add text to file RRS feed

  • คำถาม

  • Hi

    I am trying to get the content of a file or multiple files, if a pattern exists within the files, i want to start a new line after the pattern, and then add some content. Below is what i have started with, any help or advice would be great. I want to add the line at the bottom after the pattern, but i am stuck.

    $IKey = xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxxx
    $fileName = "C:\TempPath\ApplicationInsights.config"
    $content = "<InstrumentationKey>$IKey</InstrumentationKey>"
    $line = <ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings">
    Get-Content $fileName | 
        Foreach-Object {
            if ($_ -match $line) 
            {
                Add-content $fileName "`n$content"
            }



    Thanks

    Shane


    • แก้ไขโดย Shane W 18 เมษายน 2562 11:17
    18 เมษายน 2562 10:47

คำตอบ

ตอบทั้งหมด