Microsoft.Update.AutoUpdate  NotificationLevel

Im working with PS Studio.

I wrote this script.

It isnt working aswell. As you see its bottom click. But when I open PS command prompt and hit this strings line by line, it is!

Can someone tell me why?

$checkud_Click = {


    $AUSettigns = (New-Object -com "Microsoft.Update.AutoUpdate").Settings
$AUSettigns.NotificationLevel = 1
$AUSettigns.Save

}

 
May 16th, 2015 2:06am

It is impossible to understand our question.  What is not working?
Free Windows Admin Tool Kit Click here and download it now
May 16th, 2015 3:04am

Here - try playing with this:

function Set-NotificationLevel{
    Param($Level=1)

    Try{
        $AUSettigns = (New-Object -com "Microsoft.Update.AutoUpdate").Settings
        $AUSettigns.NotificationLevel=$Level
        $AUSettigns.Save
    }
    Catch{
        Add-Type -AssemblyName System.Windows.Forms
        [System.Windows.Forms.MessageBox]::Show($_)
    }
}
May 16th, 2015 3:11am

This function isnt crash but also didnt work for me.

 As i said, i can change firewall policy by pasting this command line by line into powershell

 $AUSettigns = (New-Object -com "Microsoft.Update.AutoUpdate").Settings
        $AUSettigns.NotificationLevel=1
        $AUSettigns.Save

I need to change notificationLevel from 1 to 4 and all is work properly.

But im writing win forms, where button click have to do it for me and it is not working.

$checkud_Click = {
	#$AUSettigns = (New-Object -com "Microsoft.Update.AutoUpdate").Settings
	#$AUSettigns.NotificationLevel = 1
	#$AUSettigns.Save
	
	function Set-NotificationLevel
	{
		Param ($Level = 2)
		
		Try
		{
			$AUSettigns = (New-Object -com "Microsoft.Update.AutoUpdate").Settings
			$AUSettigns.NotificationLevel = $Level
			$AUSettigns.Save
		}
		Catch
		{
			Add-Type -AssemblyName System.Windows.Forms
			[System.Windows.Forms.MessageBox]::Show($_)
		}
	}
}





Free Windows Admin Tool Kit Click here and download it now
May 16th, 2015 6:24am

I recommend starting by learning how to write a PowerShell script.  After you know the basics you will be able to see why you cannot make this work.

Functions have to be called in order too be useful.  You are not calling anything.  That is because you do not know the simplest basic ideas which are required to write even a simple script. 

You cannot learn PowerShell by asking a lot of questions.

May 16th, 2015 9:02am

thats true mate, I thought that button_click is an event  which is holding this function inside
Free Windows Admin Tool Kit Click here and download it now
May 16th, 2015 9:08am

Hi Patrick,

According to your description, the script below to change NotificationLevel works in powershell:

$AUSettigns = (New-Object -com "Microsoft.Update.AutoUpdate").Settings
$AUSettigns.NotificationLevel=1
$AUSettigns.Save

I assume you are using Sapien PowerShell Studio to create the windows form, and you encouter issue when create button click, in this case, please follow this article to interact with Button:

Powershell and GUI : Button element

If there is anything else regarding this issue, please feel free to post back.

Best Regards,

Anna Wang

May 17th, 2015 2:47am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics