For each loop errors

Good morning experts!

Attempting to get the following to work in a foreach loop

$sub = Get-SCOMNotificationSubscription | where {$_.displayname -like "SUBSCRIPTION_NAME"}
$sub.Enabled = $true
$sub.Update($true)

Here is my foreach loop

#Enable Subscriptions
$Names = Get-SCOMNotificationSubscription | Select-Object Displayname
ForEach ($Name in $Names) {
$sub = Get-SCOMNotificationSubscription | Select-Objecte {$_.displayname -like "$Name"}
$sub.Enabled = $true
$sub.Update($true)
}

Here are the errors I’m receiving and variable outputs:

The property 'Enabled' cannot be found on this object. Verify that the property exists and can be set.
At line:6 char:1
+ $sub.Enabled = $true
+ ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyAssignmentException
 
Method invocation failed because [Selected.Microsoft.EnterpriseManagement.Administration.AlertNotificationSubscription] does not contain a method named 'Update'.
At line:7 char:1
+ $sub.Update($true)
+ ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Update:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound
 
The property 'Enabled' cannot be found on this object. Verify that the property exists and can be set.
At line:6 char:1
+ $sub.Enabled = $true
+ ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyAssignmentException
 
Method invocation failed because [Selected.Microsoft.EnterpriseManagement.Administration.AlertNotificationSubscription] does not contain a method named 'Update'.
At line:7 char:1
+ $sub.Update($true)
+ ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Update:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound
 

PS C:\Users\nlong-admin> echo $Name

DisplayName                                     
-----------                                     
StorageCompute - LIMITED - Windows 2012 OS Scope



PS C:\Users\nlong-admin> echo $Names

DisplayName                                     
-----------                                     
StorageCompute - LIMITED - Windows OS Scope     
StorageCompute - LIMITED - Windows 2012 OS Scope



PS C:\Users\nlong-admin> echo $sub

$_.displayname -like "$Name"
----------------------------
                       False
                       False

Would greatly appreciate any and all input, this should be simple but my blindness has gotten the best of me.

Norm

[pre]$a=get-process |select name,id
$a
0…($a.length-1)|%{$a[$].id=$}
$a[/pre]

Assuming this is a direct copy of your script, you have a typo on line 4 of the foreach loop:

$sub = Get-SCOMNotificationSubscription | Select-Objecte {$_.displayname -like "$Name"}

so you probably aren’t getting the information you expect stored in $sub.

Greetings all,
Finally got it to work, note the following:

#Enable Subscriptions
$Names = Get-SCOMNotificationSubscription | Where-Object { $_.DisplayName -Like "*"}
ForEach ($Name in $Names) {
$Name.Enabled = $true
$Name.Update($true)
}

Thank you for the input!!

Norm