Many thanks to you both for your replies… I fear I may have confused the situation somewhat so I shall seek to clarify the position I am in, in the way it has been articulated but Grokkit above.
- I have a bunch of fields in an excel document that is updated externally
- I am able to add fields if required, such as a date or time of entry of a new row
- I am able to convert to CSV as part of this process, if required
- The table looks similar to below, with more and more entries being added by users
Subscription Name |
Subscription Category 1 |
Subscription Category 2 |
Entered |
Sub1 |
A |
X |
1/4/20 09:00 |
Sub2 |
B |
Y |
1/4/20 09:00 |
Sub3 |
C |
Z |
1/4/20 09:00 |
Sub4 |
D |
W |
1/4/20 09:00 |
2. I have external code that I use in another application (PowerBI) that looks like the lines below. I have a means to automate this process on a schedule, so there is no need for the PowerShell to control or manage when its run.
Subscription Category 1 =
If(CONTAINS(‘Azure Subscription’,’Azure Subscription’[Subscription Name],”Sub1″),”A”
,IF(CONTAINS(‘Azure Subscription’,’Azure Subscription’[Subscription Name],”Sub2″),”B”
,IF(CONTAINS(‘Azure Subscription’,’Azure Subscription’[Subscription Name],”Sub3″),”C”
Subscription Category 2 =
If(CONTAINS(‘Azure Subscription’,’Azure Subscription’[Subscription Name],”Sub1″),”X”
,IF(CONTAINS(‘Azure Subscription’,’Azure Subscription’[Subscription Name],”Sub2″),”Y”
,IF(CONTAINS(‘Azure Subscription’,’Azure Subscription’[Subscription Name],”Sub3″),”Z”
This can be stored in any file type, such as .txt if easiest. I simply used PowerShell ISE when doing this manually as it made if easier for me to format and idefity the fields I was manually updating/adding
- As per my example in the table above, a user has entered a new line “Sub4”. I would like to create a PowerShell script that opens this spreadsheet (potentially converting to CSV first?) and updates the PowerBI code in an output file. In the example above, this would result in the output file now looking like below, with the bold values identifying what has been pulled from the CSV.
Subscription Category 1 =
If(CONTAINS(‘Azure Subscription’,’Azure Subscription’[Subscription Name],”Sub1″),”A”
,IF(CONTAINS(‘Azure Subscription’,’Azure Subscription’[Subscription Name],”Sub2″),”B”
,IF(CONTAINS(‘Azure Subscription’,’Azure Subscription’[Subscription Name],”Sub3″),”C”
,IF(CONTAINS(‘Azure Subscription’,’Azure Subscription’[Subscription Name],”Sub4″),”D”
Subscription Category 2 =
If(CONTAINS(‘Azure Subscription’,’Azure Subscription’[Subscription Name],”Sub1″),”X”
,IF(CONTAINS(‘Azure Subscription’,’Azure Subscription’[Subscription Name],”Sub2″),”Y”
,IF(CONTAINS(‘Azure Subscription’,’Azure Subscription’[Subscription Name],”Sub3″),”Z”
,IF(CONTAINS(‘Azure Subscription’,’Azure Subscription’[Subscription Name],”Sub4″),”W”
Does that make sense now?