# Issue in editing conf file through script

**URL:** https://forums.powershell.org/t/issue-in-editing-conf-file-through-script/5631
**Category:** PowerShell Help
**Created:** [January 28, 2016, 12:16am UTC](https://forums.powershell.org/t/issue-in-editing-conf-file-through-script/5631 "2016-01-28T00:16:57Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![ankit-parmar](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@ankit-parmar](https://forums.powershell.org/u/ankit-parmar)
#### Post date: [January 28, 2016, 12:16am UTC](https://forums.powershell.org/t/issue-in-editing-conf-file-through-script/5631/1 "2016-01-28T00:16:57Z")

</div>

Hi,

I have one file (inputs.conf) which i want to edited through script. I am pasting first 3 lines of the inputs.conf file below to get script easily understand -

#[SplunkAzure://Collection1]  
#storageAccountKey = Your storage account key  
#storageAccountName = Your storage account name

Now i have a script given below -

$webConfig = ‘C:\Program Files\SplunkUniversalForwarder\etc\apps\SplunkAzure\local\inputs.conf’  
Get-Content $webConfig  
$obj = ‘SplunkAzure://Collection1’ | where {$\_storageAccountKey -eq ‘Your storage account key’}  
$obj.storageAccountKey = ‘78945’

Now when i am trying to replace “78945” with ‘Your storage account key’ its given below error -

The property ‘storageAccountKey’ cannot be found on this object. Verify that the property exists and can be set.At D:\Ankit\data\CentOS\New folder\scripts\inputsfile.ps1:4 char:1

- $obj.storageAccountKey = ‘78945’ … Any suggestions … Kindly advise…

Thanks  
Ankit

---

<div class="post-metadata">

### Author: ![\_timpringle](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/_timpringle/32/276_2.png) [@\_timpringle](https://forums.powershell.org/u/_timpringle)
#### Post date: [January 28, 2016, 12:22am UTC](https://forums.powershell.org/t/issue-in-editing-conf-file-through-script/5631/2 "2016-01-28T00:22:57Z")

</div>

Hi Ankit,

I don’t see anywhere that you are setting $obj to have these properties.

```
$obj = 'SplunkAzure://Collection1' | where {$_storageAccountKey -eq 'Your storage account key'}
```

Will just treat ‘SplunkAzure://Collection1’ as a string, and will always return a null value from that statement.

---

<div class="post-metadata">

### Author: ![ankit-parmar](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@ankit-parmar](https://forums.powershell.org/u/ankit-parmar)
#### Post date: [January 28, 2016, 12:27am UTC](https://forums.powershell.org/t/issue-in-editing-conf-file-through-script/5631/3 "2016-01-28T00:27:09Z")

</div>

thanks for your input Tim … do you suggest me or else make corrections in my script so that i will do it for the rest other part.

Thanks  
Ankit

---

<div class="post-metadata">

### Author: ![\_timpringle](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/_timpringle/32/276_2.png) [@\_timpringle](https://forums.powershell.org/u/_timpringle)
#### Post date: [January 28, 2016, 1:49am UTC](https://forums.powershell.org/t/issue-in-editing-conf-file-through-script/5631/4 "2016-01-28T01:49:43Z")

</div>

The format of the file you show appears to be of a .ini type.

As you’re doing a straightforward replace, then i’d suggest a better idea might be to do something like the following

```
$fileContent = Get-Content D:\temp\test.txt | Out-String 
  $fileContent = $fileContent -replace 'our storage account key','78945'
  $fileContent | Out-File -FilePath d:\temp\test.txt -force
```

---

<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:43pm UTC](https://forums.powershell.org/t/issue-in-editing-conf-file-through-script/5631/5 "2024-05-16T20:43:01Z")

</div>


