Archive for June, 2009

Prevent desktop lock or screensaver with PowerShell

Imagine that there’s a webcast that you absolutely need to record and your girlfriend calls because she had a bad dream and you need to go to give her consolation, or it’s your daughter’s birthday, or simply 11 pm because the Earth is huge and the timezones suck. Your first reaction is to simply try to record the webcast but this is a corporate PC and group policy is configured to lock the desktop after x minutes of inactivity. What do you do?

I found myself in this situation a few days ago, and did not want to search the internet and download a random executable simulating user activity and doing who knows what else on my computer.

Instead I wrote this simple PowerShell script:

param($minutes = 60)

$myshell = New-Object -com "Wscript.Shell"

for ($i = 0; $i -lt $minutes; $i++) {
  Start-Sleep -Seconds 60
  $myshell.sendkeys(".")
}

All the script does is creates a Windows scripting shell com object, and then for the specified number of minutes (which is a script parameter) every minute presses the “.” key.

Then I saved the script as Prevent-Screensaver.ps1 file (“prevent” is not a proper PowerShell verb, but disable- or stop- do not seem quite right…) and started it from PowerShell command-line: & c:\Prevent-Screensaver.ps1 120

One other thing which I also did was starting a notepad and clicking into it. This made the script output the dots into the application rather than overload Windows input buffer (which would have caused the OS to start beeping.)

Oh, and before anyone adds comments on how I have just ruined desktop security in the enterprise… By using this you might be circumventing security measures which your company might have for a reason. Check with your HR/IT/legal department/manager when in doubt. 😉

[UPDATE] Check out what Claus posted in his comments here – an even better way of preventing the screensaver by moving the mouse cursor a bit.

Tags: ,

Exchange 14 PowerGUI wallpaper

Oz (Exchange MVP doing a great series of Exchange/PowerShell/PowerGUI How-To’s) has also posted a bunch of Exchange 2010 desktop wallpapers – one of them featuring PowerGUI.

Download them here.

Tags: , , ,

Add great HTML reports to PowerGUI

Kirk has recently published a PowerPack which adds really nice-looking reports to PowerGUI Admin Console. Once you install the pack you will get these reports for any systems you manage: AD, Exchange, Operations Manager, VMware, Hyper-V – you name it.

See this video for details:

Download the PowerPack here.

Tags: , , , , ,

3 cmdlets a day keep the trouble away

There’s yet another reason to follow @PowerGUIorg on Twitter.

Our friendly community site ghost now 3 times a day tweets a random PowerShell cmdlet with the cmdlet name, synopsis, and link to the cmdlet page which has detailed cmdlet information: full description, parameters, examples, and so on.

sample-powershell-tweet

This should be a great way to learn cmdlets shipped with PowerShell v2 (some are obviously present in v1 as well) in small easy chunks. 🙂

@PowerGUIorg also tweets each time a new discussion is started at PowerGUI.org forums – so you can easily get involved in any topic which you find interesting or perhaps help somebody out if you know the answer.

Follow @PowerGUIorg and let us know what you think. Any ideas on making this feed even more useful are welcome!

Tags: , , ,

Video: What’s new in PowerGUI 1.8

For those preferring seeing to reading here’s Darin’s video highlighting the major improvements introduced in PowerGUI Admin Console in version 1.8:

If you want to learn more, I also had a few blog posts on 1.8 features on my blog:

Tags: , , ,

AD Recovery from PowerShell

Want to roll back any Active Directory change with a PowerShell one-liner? We’ve just published an online reference to the cmdlets shipped with Quest Recovery manager for Active Directory.

These cmdlets use backups so they are not limited to tombstone reanimation (as regular cmdlets).

For example, if you restore a user you get all the attributes including group membership and so on.

So to restore a deleted object you simply call Restore-RMDeletedActiveDirectoryObject and have the tool handle everything.

However, what makes it way more cool is that you have full power to restore any attributes of any users. So you are not limited to just undeleting stuff. Let’s say you had some kind of script/tool go wild and corrupt an attribute or two across all user accounts. Good luck restoring just these 2 attributes manually or with any kind of UI tool.

With these cmdlets it is as easy as:

# Select the backup you want - e.g. the latest
$b = (Get-RMBackup –Domain dom1.local | Sort-Object –Property Date)[-1]

# For every user in AD restore extensionattribute1

Get-QADUser | foreach {
Restore-RMActiveDirectoryObject –Backup $b.Path –Object $_.DN –Attribute extensionattribute1
}

Is it cool or what? 😉

Here’s the full list of cmdlets linked to the help info for each of them:

Note that unlike AD cmdlets these are actually a part of commercial product so there is cost involved. You can get a trial license from the product page. If you are a Microsoft MVP you can also get a free NFR license by applying here.

(Get-RMDeletedActiveDirectoryObject dc1.dom1.lab.local) | Where-Object { $_.Properties["objectclass"] –contains "user" }

C:\PS>foreach ($u in $users) { Restore-RMDeletedActiveDirectoryObject –Name $u.Properties["name"] –DirectoryHost dc1.dom1.lab.local }

Tags: , , , , , , ,

Add your code snippets to PowerGUI

Want to add your PowerShell code snippets to PowerGUI Script Editor?

snippet_insert

It is actually as easy as adding your xml .snippet file to the C:\Program Files\PowerGUI\snippets folder.

You can create a new file manually or use any Visual Studio-compatible snippet editor. I am using Snipp Dogg which is a free open source project on codeplex. So my instructions below are using this tool but anything else would do.

1. Run the tool as Administrator (or it would not be able to save to Program Files if you are on Vista or later.)

2. You can see and study any of the snippet files shipped with PowerGUI:

PowerShell_Snippets

3. Click the New button to create a new snippet and then paste your code into the central pane – in my example I start with advanced function code from PowerShell v2 example:

new_snippet

4. If you want your snippet to have placeholders for certain variable names, parameters, and so on, you need to replace each of them with $some_kind_of_id$. In addition to that you can put $selected$ in front of the one you want to become selected once the snippet is inserted.

In my example, I am making the function name and the variable name these snippet parameters (in snippet lingo “literals”) and make the function name selected by default:

params

5. Fill out other snippet parameters in the right-hand pane (Snipp Dogg does not have powershell as a language option – shame on them – so either change it in the xml file later on or just leave it as csharp – PowerGUI does not check this field):

sniippet_description

6. Expand the Literals collection and click New to add a new literal (remember: we need to specify two):

snippet_new_literal

7. Fill out and save (by clicking OK) both functionname and param:

function_name_literal

snippet_param_paramname

8. Save the snippet to the C:\Program Files\PowerGUI\snippets folder (requires admin rights in Vista and later):

snippet_save

9. Start PowerGUI Script Editor and insert the snippet:

snippet_insert

snippet_inserted

That’s it! Happy scripting! 😉

Tags: , , ,

Interactive PowerGUI Blog Badges

This is part two of the PowerGUI.org blog badges instructions. In part one we learned how to add a PowerGUI graphics widget.

Today I will show how to add a widget dynamically showing your latest threads or messages at our PowerShell discussion forums.

As you can see I have one in the right-hand column of this blog and it looks like:

Thread_Widget

To add such a widget in wordpress, go to Dashboard/Appearance/Widgets, add an RSS gadget and paste the following RSS feed link (make sure you change my name to your PowerGUI.org name and replace space with %20):

http://www.powergui.org/rss/rssmessages.jspa?categoryID=55&RssUsername=Dmitry%20Sotnikov

For wordpress, the widget will then look like:

RSS_Widget

Type something like “My recent posts at PowerGUI.org” to the feed title, and select the number of items to show.

Then save the changes and you are good to go!

If you want the widget to display recent threads(rather than posts) use this RSS feed instead:

http://www.powergui.org/rss/rssthreads.jspa?categoryID=55

That’s it. If you want to add graphics – see my previous post.

If you are on platforms other than wordpress or have other ideas of PowerGUI widgets – please post them on your blog and add the link in your comments to this post. Please help us spread the news of PowerShell, PowerGUI and PowerGUI.org to a wider community!

Tags: , , , , ,

PowerGUI Blog Badges

The easiest way to promote your favorite PowerShell tool on your blog or website is add one of our PowerGUI.org badges to it. You can borrow the images which Susan posted here or copy/paste the html code from below:

My examples below are for wordpress – this is the platform which I am using and for which I tested these. (Please post your instructions for other platforms.)

Static Images

To add these, add Text widget in your wordpress Dashboard/Appearance/Widgets and paste the corresponding html code:

For PowerShell, I love PowerGUI

<p>
<a href="http://powergui.org" title="For PowerShell, I love PowerGUI">
<img src="http://powergui.org/servlet/JiveServlet/download/118-9270-29383-3688/bn1-powergui-200x75.gif" alt="For PowerShell, I love PowerGUI" height="75" width="200" />
</a>
</p>

My PowerShell IDE is PowerGUI

<p>
<a href="http://powergui.org" title="My PowerShell IDE is PowerGUI">
<img src="http://powergui.org/servlet/JiveServlet/download/118-9270-29383-3689/bn2-powergui-200x100.gif" alt="My PowerShell IDE is PowerGUI" height="100" width="200" />
</a>
</p>

My PowerShell community is PowerGUI.org

<p>
<a href="http://powergui.org" title="My PowerShell community is PowerGUI.org">
<img src="http://powergui.org/servlet/JiveServlet/download/118-9270-29384-3690/bn1-powergui-200x100.gif" alt="My PowerShell community is PowerGUI.org" height="100" width="200" />
</a>
</p>

My PowerShell community is PowerGUI.org

<p>
<a href="http://powergui.org" title="My PowerShell community is PowerGUI.org">
<img src="http://powergui.org/servlet/JiveServlet/download/118-9270-29384-3691/bn2-powergui-200x75.gif" alt="My PowerShell community is PowerGUI.org" height="75" width="200" />
</a>
</p>

My PowerShell community is PowerGUI.org

<p>
<a href="http://powergui.org" title="My PowerShell community is PowerGUI.org">
<img src="http://powergui.org/servlet/JiveServlet/download/118-9270-29388-3695/bn5-powergui-200x75.gif" alt="My PowerShell community is PowerGUI.org" height="75" width="200" />
</a>
</p>

My PowerShell community is PowerGUI.org

<p>
<a href="http://powergui.org" title="My PowerShell community is PowerGUI.org">
<img src="http://powergui.org/servlet/JiveServlet/download/118-9270-29388-3694/bn3-powergui-200x75.gif" alt="My PowerShell community is PowerGUI.org" height="75" width="200" />
</a>
</p>

My PowerShell community is PowerGUI.org

<p>
<a href="http://powergui.org" title="My PowerShell community is PowerGUI.org">
<img src="http://powergui.org/servlet/JiveServlet/download/118-9270-29391-3697/bn4-powergui-200x75.gif" alt="My PowerShell community is PowerGUI.org" height="75" width="200" />
</a>
</p>

Instead of PowerGUI.org you can obviously link to a specific forum or even your profile page at PowerGUI.org – just click your username next to your post there to get link to that page. You profile contains whatever information you supplied and links to your latest messages.

Tomorrow I will show how you can create interactive widgets automatically showing your latest messages or threads in our forums.

If you are on platforms other than wordpress or have other ideas of PowerGUI widgets – please post them on your blog and add the link in your comments to this post. Please help us spread the news of PowerShell, PowerGUI and PowerGUI.org to a wider community!

Tags: , , , , ,

What’s new in AD cmdlets 1.2.2

As Bob blogged yesterday the latest release of Quest’s free AD cmdlets are now available for download. I wanted to take a few minutes to describe what’s actually new and changed in this release.

First and foremost – this is a maintenance release – think about it as a service pack: no new features but lots of bugfixes.

All features were introduced back in 1.2 two months ago and if you missed it have a look at the blog posts I had on these:

The key bugfixes added to 1.2.2 maintenance release are:

  • Fixed the Connection property and other incompatibility issues which affected Kirk’s AD PowerPack.
  • Made Member, MemberOf and AppliesTo properties indexable: so you can do something like $user.MemberOf[1].
  • Added the ability to connect to domain controller, ADAM/ADLDS server or ActiveRoles Server by IP address (e.g. if DNS is not set up properly.)
  • Fixed TsHomeDrive and TsHomeDirectory bug reported by Shay.
  • And finally enhanced the setup so it ensures compatibility with ActiveRoles Server should you have this product deployed.

Overall a good service release and the one we plan to make our minimal system requirement for AD PowerPack starting with PowerGUI 1.9.

Download it here.

Tags: , , , ,


My Recent Tweets

Legal

The posts on this blog are provided “as is” with no warranties and confer no rights. The opinions expressed on this site are mine and mine alone, and do not necessarily represent those of my employer - WSO2 or anyone else for that matter. All trademarks acknowledged.

© 2007-2014 Dmitry Sotnikov

June 2009
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

%d bloggers like this: