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