ConvertFrom-StringData Data Item already defined.

Hello.

I am trying to parse multiply emails from a folder in Outlook, whenever I run the script on 1 user the script runs perfectly.

When I run the script on two users, ConvertFrom-StringData throws me an error;

ConvertFrom-StringData : Data item 'Medarbejdertype' in line 'Medarbejdertype=Praktikant' is already defined. At C:\Users\Steve\OneDrive\PowerShell_Scripts\FITIT.ps1:21 char:99
As far as I could tell from the error output it seems like the hash-table($data in this case) did not reset itself at the end of the loop.

So I have tried to clear it with the following cmdlets/methods/declaring;

$data.clear() $data = @{} Clear-Variable -Name $data
Even through I can see that the hash-table is cleared on the second run PowerShell throws me that error stated above.

I’ve been googling, read the documentation but as far as I can tell I have used it correctly?

I don’t know if it is my understanding of line 21 that might be too poor, I recived a lot of help with that one from PowerShell slack user @Chrisdent I belive it was.

Could anyone tell me what I am doing wrong? Or maybe link me to something that could get me back on track? I feel completly lost as what the next step is.

Best Regards.

STPE

Code I am using:

https://gist.github.com/Add-STPE/e9d7993a6da6fd45a57e6dcbeb46da23

 

best way is to not to use same variable. You can change the variable name to $ConvertedData for converting from string.

I was told a solution, the problem was at line 19, It was the $html variable that needed to a reset so adding

$html = New-Object -ComObject "HTMLFile"
Above line 19 fixed the problem!