# set-content

**URL:** https://forums.powershell.org/t/set-content/7699
**Category:** PowerShell Help
**Created:** [December 12, 2016, 3:05pm UTC](https://forums.powershell.org/t/set-content/7699 "2016-12-12T15:05:25Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![tony-antony](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/tony-antony/32/192_2.png) [@tony-antony](https://forums.powershell.org/u/tony-antony)
#### Post date: [December 12, 2016, 3:05pm UTC](https://forums.powershell.org/t/set-content/7699/1 "2016-12-12T15:05:25Z")

</div>

Hello,

I have a script to put these numbers in order

[1=mkelley@company.com](mailto:1=mkelley@company.com)  
[2=jbruce@company.com](mailto:2=jbruce@company.com)  
[3=oreynolds@company.com](mailto:3=oreynolds@company.com)  
[4=JSTACK@company.com](mailto:4=JSTACK@company.com)  
[5=Dwu@company.com](mailto:5=Dwu@company.com)  
[1433=mkuss@company.com](mailto:1433=mkuss@company.com)  
[1434=ayoloye@company.com](mailto:1434=ayoloye@company.com)  
[1435=tonierras@company.com](mailto:1435=tonierras@company.com)  
[1436=sgoldsborough@company.com](mailto:1436=sgoldsborough@company.com)  
[1437=pbeavers@company.com](mailto:1437=pbeavers@company.com)  
[1438=ederengowski@company.com](mailto:1438=ederengowski@company.com)  
[1439=alippard@company.com](mailto:1439=alippard@company.com)  
[1440=klaw@company.com](mailto:1440=klaw@company.com)  
[one@company.com](mailto:one@company.com)  
[three@company.com](mailto:three@company.com)

so that it looks like

[1=mkelley@company.com](mailto:1=mkelley@company.com)  
[2=jbruce@company.com](mailto:2=jbruce@company.com)  
[3=oreynolds@company.com](mailto:3=oreynolds@company.com)  
[4=JSTACK@company.com](mailto:4=JSTACK@company.com)  
[5=Dwu@company.com](mailto:5=Dwu@company.com)  
[6=mkuss@company.com](mailto:6=mkuss@company.com)  
[7=ayoloye@company.com](mailto:7=ayoloye@company.com)  
[8=tonierras@company.com](mailto:8=tonierras@company.com)  
[9=sgoldsborough@company.com](mailto:9=sgoldsborough@company.com)  
[10=pbeavers@company.com](mailto:10=pbeavers@company.com)  
[11=ederengowski@company.com](mailto:11=ederengowski@company.com)  
[12=alippard@company.com](mailto:12=alippard@company.com)  
[13=klaw@company.com](mailto:13=klaw@company.com)  
[14=one@company.com](mailto:14=one@company.com)  
[15=three@company.com](mailto:15=three@company.com)

The problem is that the below Set-Content appends only [15=three@company.com](mailto:15=three@company.com), and deletes the original text.

```
$INI_Location = "\\hqfs1\users\tantony\PowerShell\CalenderGroup\config.ini"
    $Read_INI = Get-Content $INI_Location
For($Index=0; $Index -lt $List_of_Users.length; $Index++)
            {            
                $Email = ($List_of_Users[$Index]) -creplace '^[^=]*=', ''
                $Index_Plus_One = $Index + 1
                $Re_Index = "$Index_Plus_One=$Email"
                $Re_Index | Set-Content $INI_Location -Force

                Write-Host $Re_Index
            }
```

Thanks,

Tony

---

<div class="post-metadata">

### Author: ![rob-simmers](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rob-simmers/32/1010_2.png) [@rob-simmers](https://forums.powershell.org/u/rob-simmers)
#### Post date: [December 12, 2016, 3:22pm UTC](https://forums.powershell.org/t/set-content/7699/2 "2016-12-12T15:22:22Z")

</div>

You are calling Set-Content in your loop, so the last enumerated line will be set overwriting the file. Take a look at this simplified logic:

```
$results = foreach ($line in (Get-Content "C:\Users\Rob\Desktop\Archive\config.ini")) {
    "{0}={1}" -f $line.ReadCount, ($line -creplace '^[^=]*=', '')
}

$results | Set-Content "C:\Users\Rob\Desktop\Archive\config.ini"
```

---

<div class="post-metadata">

### Author: ![tony-antony](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/tony-antony/32/192_2.png) [@tony-antony](https://forums.powershell.org/u/tony-antony)
#### Post date: [December 12, 2016, 3:33pm UTC](https://forums.powershell.org/t/set-content/7699/3 "2016-12-12T15:33:40Z")

</div>

I figured it out, thanks. I forgot to actually write the files before set-content

---

<div class="post-metadata">

### Author: ![tony-antony](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/tony-antony/32/192_2.png) [@tony-antony](https://forums.powershell.org/u/tony-antony)
#### Post date: [December 12, 2016, 3:45pm UTC](https://forums.powershell.org/t/set-content/7699/4 "2016-12-12T15:45:35Z")

</div>

Writing powershell on less sleep, not paying attention to details 🙂

---

<div class="post-metadata">

### Author: ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)
#### Post date: [May 16, 2024, 8:39pm UTC](https://forums.powershell.org/t/set-content/7699/5 "2024-05-16T20:39:46Z")

</div>


