Skip to main content
added 783 characters in body
Source Link

In your listed code, you declare the variable $lookupvalue1 but further down you use $lookupvalue (missing the '1'). I'm assuming you changed this and forgot about it and it is still working without throwing errors because it's using an older object.

To help prevent such mistakes, you could enable strict mode by adding this at the top of your script:

Set-Strictmode -Version Latest

EDIT:

#This LookupId returns 3 values like so :1,2,6
$lookupvalue.LookupId = $number

I don't see how it does. LookupId is an int. It contains a single value. As such you must assign a single value. There's no way it can return 3 values.

$itemValues.Add($lookupvalue)
$CMRSItems["Event Type"] = $itemValues;

Seeing this, you started out correctly, but adding item X to collection Y and assigning collection Y to your field, Z amount of times still only leaves one value in your field, not Z values, because it was overwritten each time.

What I think you want to do is loop as you are now, but keep adding the $lookupvalue to $itemValues each time and below your loop, assign $itemValues to $CMRSItems["Event Type"]

In your listed code, you declare the variable $lookupvalue1 but further down you use $lookupvalue (missing the '1'). I'm assuming you changed this and forgot about it and it is still working without throwing errors because it's using an older object.

To help prevent such mistakes, you could enable strict mode by adding this at the top of your script:

Set-Strictmode -Version Latest

In your listed code, you declare the variable $lookupvalue1 but further down you use $lookupvalue (missing the '1'). I'm assuming you changed this and forgot about it and it is still working without throwing errors because it's using an older object.

To help prevent such mistakes, you could enable strict mode by adding this at the top of your script:

Set-Strictmode -Version Latest

EDIT:

#This LookupId returns 3 values like so :1,2,6
$lookupvalue.LookupId = $number

I don't see how it does. LookupId is an int. It contains a single value. As such you must assign a single value. There's no way it can return 3 values.

$itemValues.Add($lookupvalue)
$CMRSItems["Event Type"] = $itemValues;

Seeing this, you started out correctly, but adding item X to collection Y and assigning collection Y to your field, Z amount of times still only leaves one value in your field, not Z values, because it was overwritten each time.

What I think you want to do is loop as you are now, but keep adding the $lookupvalue to $itemValues each time and below your loop, assign $itemValues to $CMRSItems["Event Type"]

added 217 characters in body
Source Link

In your listed code, you declare the variable $lookupvalue1 but further down you use $lookupvalue (missing the '1'). I'm assuming you changed this and forgot about it and it is still working without throwing errors because it's using an older object.

To help prevent such mistakes, you could enable strict mode by adding this at the top of your script:

Set-Strictmode -Version Latest

In your listed code, you declare the variable $lookupvalue1 but further down you use $lookupvalue (missing the '1'). I'm assuming you changed this and forgot about it and it is still working without throwing errors because it's using an older object.

In your listed code, you declare the variable $lookupvalue1 but further down you use $lookupvalue (missing the '1'). I'm assuming you changed this and forgot about it and it is still working without throwing errors because it's using an older object.

To help prevent such mistakes, you could enable strict mode by adding this at the top of your script:

Set-Strictmode -Version Latest
Source Link

In your listed code, you declare the variable $lookupvalue1 but further down you use $lookupvalue (missing the '1'). I'm assuming you changed this and forgot about it and it is still working without throwing errors because it's using an older object.