Posts Tagged 'Windows PowerShell'

PowerShell script to set Skype status text to latest blog or twitter update

In my current company (Jelastic) we have something happening to us all the time: latest blog posts, awards, media mentions, etc. We are doing a decent job pushing these to various social media, but I also wanted to get these to my contacts in Skype (Skype gives you the ability to set your status text in your profile).

Below is the PowerShell v3 script that I wrote today to do that! 🙂

It takes the latest item from my blog and twitter feed, sees which of them is fresher, and (unless the tweet is just my reply to someone) pushes that to Skype (the property is called MoodText).

Here’s the script:

###################################################
# Set-SkypeStatusText.ps1
# Gets latest post from RSS feed (e.g. blog) and Twitter
# Picks whichever is the latest and sets it as status text (MoodText) in Skype
# (unless the latest tweet is a reply)
#
# NOTE: On x64 boxes, use PowerShell x86 (for Skype compat)
#
##################################################
# (c) 2012 - Dmitry Sotnikov
##################################################

# Customize these for yourself
$myblog = "http://blog.jelastic.com/feed/"
$myTwitterHandle = "DSotnikov"

# Get the blog feed
$blogFeed = Invoke-RestMethod $myblog

# Get the twitter feed
$twitterFeed = Invoke-RestMethod `
"https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=$myTwitterHandle"


# If twitter is more recent and not a reply (does not start with @) use it
if (($twitterFeed[0].pubDate -gt $blogFeed[0].pubDate) -and
($twitterFeed[0].description[$myTwitterHandle.Length+2] -ne "@")){
$latestPost = $twitterFeed[0].description.Substring($myTwitterHandle.Length+2)
} else {
$latestPost = "$($blogFeed.Item(0).title): $($blogFeed.Item(0).link)"
}

# Set the status in twitter
$skype = New-Object -ComObject Skype4Com.Skype
$skype.CurrentUserProfile.MoodText = $latestPost

Now if you want to have this happen automatically you can just schedule it using Windows Task Scheduler.

Important:

  • Make sure that you use 32-bit (x86) version of PowerShell if you are on 64-bit Windows – otherwise Skype object will not get found (so the filepath for the Windows task on x64 Windows will likely be %SystemRoot%\syswow64\WindowsPowerShell\v1.0\powershell.exe)
  • Either sign your script or set ExecutionPolicy to RemoteSigned – otherwise the script execution will fail.
Advertisement

Call for Sessions for PowerShell Deep Dive 2012 – San Diego, CA – April 29 – May 2

PowerShell Deep Dive and The Experts Conference 2012

In case you missed the announcement from the PowerShell team at Microsoft, it is time to register for PowerShell Deep Dive 2012!

PowerShell Deep Dive is the most advanced PowerShell conference of the year with level 400 sessions and all main PowerShell MVPs and movers and shakers, as well as the PowerShell team members attending and presenting.

This year, it will be a full 3 day long conference with tons of great content and a lot of PowerShell v2 and v3 stuff – so don’t miss your chance and register today to get the early bird discount.

Even more importantly, the call for session proposals is still open till February 15. So if you have a few cool topics to preset, want to share your knowledge, become a star, and get your conference pass, travel and registration paid for (!) send your session abstracts to TEC2012@quest.com ASAP.

See videos from the Deep Dive 2011 here.

See you in San Diego!

 

 

Reset PowerShell Runspace in PowerGUI Script Editor

Here’s another neat feature we have added in PowerGUI 3.0 – ability to reset PowerShell runspace when you need to.

All you have to do is:

  • Go to Debug menu, and click Reset Runspace.

And that will give you a nice new shiny PowerShell session with no variables or other changes left from your preceding work!

You can also make PowerGUI automatically reset runspace each time you start debugging if you:

  1. On the Tools menu, click Options,
  2. On Debug Options tab, select Reset PowerShell runspace each time debugging is started.

I somehow prefer manual method to automated one because quite often there is value in left-over variables (you get intellisense for example!), loaded modules, and so on. However, I can then manually reset the runspace before my final debug session to make sure the script works fine in a clean environment.

Either way, now you have both options at your command! Happy scripting!

(Screenshot taken from the original PowerGUI 3.0 announcement which lists a lot of other great features we shipped in that release)

Video: Bruce Payette – Inside PowerShell Runtime

Here’s recording, slides and scripts from one of my favorite talks of TEC US 2011 PowerShell Deep Dive – Bruce Payette’s “Why Does it Work that Way? Inside the PowerShell Runtime”

This session was recorded live at The Experts Conference.

Session abstract:

PowerShell is a unique environment, combining features from shell, scripting and object-oriented programming languages. In this session recorded at The Experts Conference 2011 PowerShell Deep Dive, Bruce Payette explores some of the trade-offs and design decisions that were made in order to produce a workable system.

Part 1:

Part 2:

This is a live recording from US TEC 2011 PowerShell Deep Dive conference. TEC Europe is just around the corner – October 17-19th, 2011 in Frankfurt. Register today to get a discount.

See also:

Show your support: Vote for AD cmdlets, PowerShell, and PowerGUI

If Get-QADUser (or any other QAD cmdlet) or PowerGUI ever saved your day – now is a good time to show your love and spread the news. 🙂

Windows IT Pro magazine put us in their community award finals. So if you want to show your support:

1. Simply go to the award voting page,

2. For the first nomination, Best Active Directory & Group Policy Product, pick Quest Software ActiveRoles Management Shell for Active Directory (who would have thought that the official name was so long):

3. And obviously leave them a note in the Give us a killer quote about your winner! box.

4. Also, believe it or not 17. Best Microsoft Product has PowerShell as one of the options.

5. 21. Best Scripting Tool has Quest Software PowerGUI:

6. And obviously feel free to either ignore all other categories or cast your vote there as well.

Cast your vote now – before the contest is over.

Clean up expired certificates from AD

Security MVP Vadims Podans just did a great post on using PowerShell to remove expired user certificates from Active Directory.

In a nutshell,

  • If your company is using certificates for user authentication or encryption, these expire every now and then,
  • Your Enterprise CA in that case appends new certificates to users’ userCertificate attribute, while leaving expired certs there as well,
  • Over time these increasingly clutter your AD, making administration more difficult and negatively affecting AD replication traffic.

Luckily, cleaning up expired certificates with PowerShell is extremely easy.

To do the clean-up for a specific user you can run this one-liner:

Get-QADUser username | Remove-QADCertificate -Valid:$false

To clean-up the entire domain, just do:

Get-QADUser | Remove-QADCertificate -Valid:$false

See Vadim’s original post for details.

Read more about PKI management with PowerShell here.

Compile PowerShell scripts to exe

Script compilation to executable files is one of the features we have added in PowerGUI Pro 3.0.

You would likely want to use compile a script when you want to share it in the enterprise environment and you are not sure whether the other person is comfortable running scripts or you simply don’t want risking someone modifying the code.

To compile a PowerShell script:

  1. Open the script in PowerGUI Pro Script Editor,
  2. On the Tools menu, click Compile Script,
  3. Then specify the name and path for the exe file you want to create:

PowerShell Compiled scripts

The additional options you get are:

  • Show or hide the PowerShell Console window when executing the script,
  • Automatically close or keep the console window (if you do want to show it),
  • Protect the script source code by obfuscating it using a password you specify,
  • Add other PowerShell scripts  to the exe (if you have script which your main script is using).

[UPDATE] If your script access parameters – so will the exe file it generates. So for an executable generated from a script like:

param ($MyParam1, $MyParam2) "MyParam1: $MyParam1""MyParam2: $MyParam2"

You may use a command line like:
c:\Generated.exe -Arguments -MyParam2 "Value2" -MyParam1 "Value1"

 

To try this feature, you can install a trial version of PowerGUI Pro from here.

(Screenshot taken from the original PowerGUI 3.0 announcement which lists a lot of other great features we shipped in that release)

Deep Dive video: PowerShell Modules by Dan Harman

We are finally starting to publish the recordings from the first PowerShell Deep Dive we had at The Experts Conference 2011 in Las Vegas in spring. We are starting with this session on patters and practices for PowerShell modules by Dan Harman – program manager on the Windows PowerShell team.

And by the way, there’s still time to register for the next PowerShell Deep Dive – October 17 & 18, 2011 in Frankfurt, Germany. Here are the instructions on getting a discount when registering.

If you want to be at the next PowerShell Deep Dive in person – register today!

See also:

Projects in PowerGUI Script Editor

Adam’s latest add-on gave me something I wanted to have in the script editor for a long time – the project tree where I can easily access files for each of my PowerShell projects, conveniently grouped together in a hierarchy.

1. Just unzip the add-on to your Documents\WindowsPowerShell\Modules folder.

2. Turn it on in File / PowerShell Libraries / Add-on.ScriptExplorer.

3. And start creating folders and adding files to them (multiselect works! 🙂

Download the new add-on here and leave your comments on the add-on page or Adam’s blog to let him know what you think!


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

March 2023
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  

%d bloggers like this: