{"id":51833,"date":"2009-12-09T00:01:00","date_gmt":"2009-12-09T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2009\/12\/09\/hey-scripting-guy-how-can-i-use-wmi-to-set-the-screen-saver-timeout-value-on-workstations\/"},"modified":"2009-12-09T00:01:00","modified_gmt":"2009-12-09T00:01:00","slug":"hey-scripting-guy-how-can-i-use-wmi-to-set-the-screen-saver-timeout-value-on-workstations","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/hey-scripting-guy-how-can-i-use-wmi-to-set-the-screen-saver-timeout-value-on-workstations\/","title":{"rendered":"Hey, Scripting Guy! How Can I Use WMI to Set the Screen Saver Timeout Value on Workstations?"},"content":{"rendered":"<p class=\"MsoNormal\"><a class=\"addthis_button\" href=\"http:\/\/www.addthis.com\/bookmark.php?v=250&amp;pub=scriptingguys\"><img decoding=\"async\" alt=\"Bookmark and Share\" src=\"http:\/\/s7.addthis.com\/static\/btn\/v2\/lg-share-en.gif\" width=\"125\" height=\"16\"><\/a>     &nbsp;&nbsp;<\/p>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n<p><font size=\"2\"><img decoding=\"async\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"><\/font><\/p>\n<p class=\"MsoNormal\">Hey Scripting Guy! I have been trying to set the screen saver time out value on my workstations by using WMI. It is not working. Can you help me get WMI working?<\/p>\n<p class=\"MsoNormal\">&#8212; HR<\/p>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n<p class=\"MsoNormal\"><img decoding=\"async\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\">Hello HR, <\/p>\n<p class=\"MsoNormal\">Microsoft Scripting Guy Ed Wilson here. My teapot is empty. I was getting ready to head downstairs to fix me a nice pot of Constant Comment tea, but Outlook dinged at me signaling that your e-mail had arrived in the <a href=\"http:\/\/blogs.technet.commailto:scripter@microsoft.com\"><font face=\"Segoe\">scripter@microsoft.com<\/font><\/a> alias. I love it when an e-mail is short, sweet, and to the point. Because I get several hundred e-mail messages a week. Long, convoluted messages tend to get shuffled to the bottom of the pile. Eventually, they get answered, but short ones are easier to deal with. The short answer is that WMI is probably already working just fine. The problem is that it does not allow you to modify the screen saver timeout value. <\/p>\n<p class=\"Readeraidonly\">Note: Portions of today&#8217;s Hey, Scripting Guy! post are excerpted from the Microsoft Press book, <i>Windows PowerShell 2.0 Best Practices<\/i> by Ed Wilson, which is now <a href=\"http:\/\/bit.ly\/edwilsonbestpractices\">available for pre-order<\/a>. <\/p>\n<p class=\"MsoNormal\">For all the good things to be had with WMI, there are still a number of very frustrating limitations. For example, WMI is good at retrieving information, but it is not always very good at changing that information. Here is an example that illustrates the point. The <b>Win32_Desktop<\/b> WMI class provides information about desktop settings as seen here.<\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">PS C:&gt; Get-WmiObject Win32_Desktop<\/p>\n<p><br>__GENUS<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: 2<br>__CLASS<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: Win32_Desktop<br>__SUPERCLASS<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: CIM_Setting<br>__DYNASTY<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: CIM_Setting<br>__RELPATH<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: Win32_Desktop.Name=&#8221;NT AUTHORITY\\SYSTEM&#8221;<br>__PROPERTY_COUNT<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: 21<br>__DERIVATION<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: {CIM_Setting}<br>__SERVER<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span>: MRED1<br>__NAMESPACE<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: rootcimv2<br>__PATH<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: \\MRED1rootcimv2:Win32_Desktop.Name=&#8221;NT AUTHORITY\\SY<br><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>STEM&#8221;<br>BorderWidth<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: 1<br>Caption<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>:<br>CoolSwitch<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>:<br>CursorBlinkRate<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: 500<br>Description<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>:<br>DragFullWindows<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: True<br>GridGranularity<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>:<br>IconSpacing<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>:<br>IconTitleFaceName<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: Segoe UI<br>IconTitleSize<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: 9<br>IconTitleWrap<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: True<br>Name<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: NT AUTHORITYSYSTEM<br>Pattern<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span>: (None)<br>ScreenSaverActive<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: True<br>ScreenSaverExecutable : C:Windowssystem32logon.scr<br>ScreenSaverSecure<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: True<br>ScreenSaverTimeout<span>&nbsp;&nbsp;&nbsp; <\/span>: 600<br>SettingID<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>:<br>Wallpaper<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>:<br>WallpaperStretched<span>&nbsp;&nbsp;&nbsp; <\/span>: False<br>WallpaperTiled<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>:<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n<p class=\"MsoNormal\">As you can see from the properties and values that are returned from the <b>Get-WmiObject<\/b> cmdlet, much of the information is valuable. Items such as screen saver timeout values and secure screen saver are of routine concern to many network administrators. While it is true these values can, and in most cases should, be set via Group Policy, there are times when network administrators want the ability to change these values via script. If you use the <b>Get-Member<\/b> cmdlet to examine the properties of the <b>Win32_Desktop<\/b> WMI class, you will be greeted with the following information.<\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">PS C:&gt; Get-WmiObject Win32_Desktop | Get-Member<\/p>\n<p><br><span>&nbsp;&nbsp; <\/span>TypeName: System.Management.ManagementObject#rootcimv2Win32_Desktop<\/p>\n<p>Name<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>MemberType<span>&nbsp;&nbsp; <\/span>Definition<br>&#8212;-<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>&nbsp;&nbsp;&nbsp;<\/span>&#8212;&#8212;&#8212;-<span>&nbsp;&nbsp; <\/span>&#8212;&#8212;&#8212;-<br>BorderWidth<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.UInt32 BorderWidth {get;set;}<br>Caption<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.String Caption {get;set;}<br>CoolSwitch<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.Boolean CoolSwitch {get;set;}<br>CursorBlinkRate<span>&nbsp; <\/span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span>Property<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.UInt32 CursorBlinkRate {get;set;}<br>Description<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.String Description {get;set;}<br>DragFullWindows<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.Boolean DragFullWindows {get;set;}<br>GridGranularity<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.UInt32 GridGranularity {get;set;}<br>IconSpacing<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.UInt32 IconSpacing {get;set;}<br>IconTitleFaceName<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.String IconTitleFaceName {get;set;}<br>IconTitleSize<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.UInt32 IconTitleSize {get;set;}<br>IconTitleWrap<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.Boolean IconTitleWrap {get;set;}<br>Name<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.String Name {get;set;}<br>Pattern<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.String Pattern {get;set;}<br>ScreenSaverActive<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.Boolean ScreenSaverActive {get;set;}<br>ScreenSaverExecutable Property<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.String ScreenSaverExecutable {get;&#8230;<br>ScreenSaverSecure<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.Boolean ScreenSaverSecure {get;set;}<br>ScreenSaverTimeout<span>&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.UInt32 ScreenSaverTimeout {get;set;}<br>SettingID<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.String SettingID {get;set;}<br>Wallpaper<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.String Wallpaper {get;set;}<br>WallpaperStretched<span>&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.Boolean WallpaperStretched {get;set;}<br>WallpaperTiled<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.Boolean WallpaperTiled {get;set;}<br>__CLASS<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.String __CLASS {get;set;}<br>__DERIVATION<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.String[] __DERIVATION {get;set;}<br>__DYNASTY<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.String __DYNASTY {get;set;}<br>__GENUS<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.Int32 __GENUS {get;set;}<br>__NAMESPACE<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.String __NAMESPACE {get;set;}<br>__PATH<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.String __PATH {get;set;}<br>__PROPERTY_COUNT<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.Int32 __PROPERTY_COUNT {get;set;}<br>__RELPATH<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.String __RELPATH {get;set;}<br>__SERVER<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.String __SERVER {get;set;}<br>__SUPERCLASS<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>System.String __SUPERCLASS {get;set;}<br>ConvertFromDateTime<span>&nbsp;&nbsp; <\/span>ScriptMethod System.Object ConvertFromDateTime();<br>ConvertToDateTime<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>ScriptMethod System.Object ConvertToDateTime();<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n<p class=\"MsoNormal\">When you use the <b>filter<\/b> parameter to get a specific instance of the <b>Win32_Desktop<\/b> WMI class and store it in a variable, you can directly access the properties of the class. In this example we need to escape the backward slash that is used as a separator between <b><span>NT Authority<\/span><\/b><span> <\/span>and <b><span>System<\/span><\/b>. This is shown here. <\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">PS C:&gt; $desktop = Get-WmiObject Win32_Desktop -Filter `<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">&gt;&gt; &#8220;name = &#8216;NT AUTHORITY\\SYSTEM'&#8221;<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n<p class=\"MsoNormal\">After you have access to a specific instance of the WMI class, you can assign a new value for the <b>ScreenSaverTimeout<\/b> parameter. As shown here, the value is updated immediately:<\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">PS C:&gt; $Desktop.ScreenSaverTimeout = 300<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">PS C:&gt; $Desktop.ScreenSaverTimeout<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">300<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n<p class=\"MsoNormal\">However, if you resubmit the WMI query, you will see that the <b>ScreenSaverTimeout<\/b> property was not updated. The <b>get:set<\/b> that is reported by the <b>Get-Member<\/b> cmdlet is related to the copy of the object that is returned by the WMI query, and not to the actual instance of the object represented by the WMI class. This is seen here:<\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">PS C:&gt; $desktop = Get-WmiObject Win32_Desktop -Filter `<br>&gt;&gt; &#8220;name = &#8216;NT AUTHORITY\\SYSTEM'&#8221;<br>&gt;&gt;<br>PS C:&gt; $Desktop.ScreenSaverTimeout<br>600 <\/p>\n<p><\/font><\/span><\/p>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n<p class=\"MsoNormal\">To set the screen saver timeout value, you will need to edit the registry. The GetSetScreenSaverTimeOut.ps1 script uses the <b>Set-ItemProperty<\/b> cmdlet to assign a new value to the <b>ScreenSaverTimeout<\/b> registry key. The GetSetScreenSaverTimeOut.ps1 script accepts two command-line parameters. The first parameter is a debug switch, and the second is the new screen saver timeout value you wish to set.<\/p>\n<p class=\"MsoNormal\">The <b>Get-ItemProperty<\/b> cmdlet is used to read the current value of the screen saver timeout value from the registry. It accepts the path to the registry key and the name of the registry property. The <b>Get-RegistryValue<\/b> function calls the <b>Get-ItemProperty<\/b> cmdlet and stores the returned value in the <b>$in<\/b> reference variable. The <b>Get-RegistryValue<\/b> function is seen here:<\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">Function Get-RegistryValue([ref]$in)<br>{<br><span>&nbsp;<\/span>Write-Debug $MyInvocation.MyCommand.name<br><span>&nbsp;<\/span>$in.value = (Get-ItemProperty -path $path -name $name).$name<br>} #end Get-RegistryValue<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n<p class=\"MsoNormal\">The <b>Set-ItemProperty<\/b> cmdlet accepts the path to the registry key, the name of the registry property to modify, and the new value to assign to the registry key. This is seen in the <b>Set-RegistryValue<\/b> function:<\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">Function Set-RegistryValue($value)<br>{<br><span>&nbsp;<\/span>Write-Debug $MyInvocation.MyCommand.name<br><span>&nbsp;<\/span>Set-ItemProperty -Path $path -name $name -value $value<br>} #end Get-RegistryValue<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n<p class=\"MsoNormal\">The <b>Write-Feedback<\/b> function is used to display the value stored in the screen saver timeout registry key. This function is seen here:<\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">Function Write-Feedback($in)<br>{<br><span>&nbsp;<\/span>Write-Debug $MyInvocation.MyCommand.name<br><span>&nbsp;<\/span>&#8220;The $name is set to $($in)&#8221;<br>} #end Write-Feedback<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n<p class=\"MsoNormal\">If the script is run with the <b>&ndash;debug<\/b> switch, the <b>Write-Debug<\/b> cmdlet will display additional information on the screen. This is seen here:<\/p>\n<p class=\"Fig-Graphic\"><span><img decoding=\"async\" title=\"Image of Write-Debug cmdlet displaying additional information on screen\" alt=\"Image of Write-Debug cmdlet displaying additional information on screen\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/december\/hey1209\/hsg-12-9-9-1.jpg\" width=\"600\" height=\"198\"><a href=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/december\/hey1209\/hsg-12-9-9-1.jpg\"><font face=\"Segoe\"><\/font><\/a><\/span><\/p>\n<p class=\"MsoNormal\">\n<p>&nbsp;<br><\/p>\n<p>The complete GetSetScreenSaverTimeOut.ps1 script is seen here. <\/p>\n<p class=\"CodeBlockScreenedHead\"><strong>GetSetScreenSaverTimeOut.ps1<\/strong><\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">Param([switch]$debug, $value = 120)<br>Function Get-RegistryValue([ref]$in)<br>{<br><span>&nbsp;<\/span>Write-Debug $MyInvocation.MyCommand.name<br><span>&nbsp;<\/span>$in.value = (Get-ItemProperty -path $path -name $name).$name<br>} #end Get-RegistryValue<\/p>\n<p>Function Set-RegistryValue($value)<br>{<br><span>&nbsp;<\/span>Write-Debug $MyInvocation.MyCommand.name<br><span>&nbsp;<\/span>Set-ItemProperty -Path $path -name $name -value $value<br>} #end Get-RegistryValue<\/p>\n<p>Function Write-Feedback($in)<br>{<br><span>&nbsp;<\/span>Write-Debug $MyInvocation.MyCommand.name<br><span>&nbsp;<\/span>&#8220;The $name is set to $($in)&#8221;<br>} #end Write-Feedback<\/p>\n<p># *** Entry Point ***<br>if($debug) { $DebugPreference = &#8220;continue&#8221; }<br>$path = &#8216;HKCU:Control PanelDesktop&#8217;<br>$name = &#8216;ScreenSaveTimeOut&#8217;<br>$in = $null<\/p>\n<p>Get-RegistryValue([ref]$in)<br>Write-Feedback($in)<br>Set-RegistryValue($value)<br>Get-RegistryValue([ref]$in)<br>Write-Feedback($in)<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n<p class=\"MsoNormal\">HR, that is all there is to setting the screen saver timeout value. WMI Week will continue tomorrow. <\/p>\n<p class=\"MsoNormal\">If you want to know exactly what we will be looking at tomorrow, follow us on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> or <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send e-mail to us at <a href=\"http:\/\/blogs.technet.commailto:scripter@microsoft.com\" target=\"_blank\"><font face=\"Segoe\">scripter@microsoft.com<\/font><\/a> or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p class=\"MsoNormal\">\n<p>&nbsp;<\/p>\n<\/p>\n<p><b><font size=\"3\"><font face=\"Times New Roman\">Ed Wilson and Craig Liebendorfer, Scripting Guys<\/font><\/font><\/b><\/p>\n<p class=\"MsoNormal\">\n<p>&nbsp;<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp;&nbsp; &nbsp; Hey Scripting Guy! I have been trying to set the screen saver time out value on my workstations by using WMI. It is not working. Can you help me get WMI working? &#8212; HR &nbsp; Hello HR, Microsoft Scripting Guy Ed Wilson here. My teapot is empty. I was getting ready to head [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[16,47,3,4,45,6],"class_list":["post-51833","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-desktop-management","tag-general-management-tasks","tag-scripting-guy","tag-scripting-techniques","tag-windows-powershell","tag-wmi"],"acf":[],"blog_post_summary":"<p>&nbsp;&nbsp; &nbsp; Hey Scripting Guy! I have been trying to set the screen saver time out value on my workstations by using WMI. It is not working. Can you help me get WMI working? &#8212; HR &nbsp; Hello HR, Microsoft Scripting Guy Ed Wilson here. My teapot is empty. I was getting ready to head [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/51833","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=51833"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/51833\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=51833"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=51833"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=51833"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}