TechProsaic

I write about great software, Internet technology, cool gadgets, and The Next Big Thing.

May 4th, 2008

How to Automate iTunes and iPod Synchronization Using PowerShell

Music Powershell

I realized lately that one thing I do every day before I leave the office is to ensure that my iPod has been sync’d recently.  It’s a major bummer to get into the car only to realize that the latest “The Guild” or “Totally Rad Show” is sitting on my computer and completely inaccessible during the long drive home.

I decided to create a scheduled task which will sync my iPod around 3:50 PM, so it’ll be ready to go when I am.  These instructions were made on a Windows XP box, the same thing applies on Vista but the steps to do it will be slightly different.  Here’s how you do it:

  1. Go to your Control Panel, Scheduled Tasks, then click on Add Scheduled Task.
    image
  2. Click Next, then Browse.
    image
  3. imageType this into the Open File dialog box and hit enter:
    %windir%\system32\windowspowershell\v1.0\powershell.exe
  4. Name the task “Sync iPod” or something like that, choose an interval (such as daily) and hit Next.
     
  5. Choose a time of day for the task to execute, and hit Next.
  6. Supply your credentials so that the task can run even when you are not logged in but your PC is on.
  7. Check the box labelled “Open Advaned Properties” and then Finish.
  8. imageClick in the Run field and hit the End key.  You should see “powershell.exe” then your cursor.  Hit the space bar, then paste in the following text, all on one line:

    -noprofile -command &{ write-host ‘Synchronizing iPod’; (New-Object -ComObject iTunes.application).UpdateIPod(); write-host ‘Sync complete!’; start-sleep 5 }

  9. Finally, click Ok. 

 

 

image

 

Now, assuming your iPod was already plugged in and iTunes is running, your iPod is not syncing at the moment.  If it is, wait till its finished so that you can test the task.  If you didn’t forsee the above, go ahead and do that; we’ll all wait for you.

And we’re back.  Now simply go the Scheduled Tasks control panel applet again, right-click on the new task and choose Run.  Within a few moments you should see that iTunes has started synchronizing.  If it does not work for you, please leave a comment and hopefully we can figure it out.

April 4th, 2008

VMware + PowerGUI = Great Combo

Powershell

Check out this blog post by Carter @ VMware.  Great stuff!

The PowerGUI VMware PowerPack has lots of great features, including the ability to manage your ESX Hosts and VMs, as well as doing bulk operations. In my opinion, PowerGUI’s best feature is that as you interact with PowerGUI, it generates PowerShell code as you go. You can take this code and re-run it later or you can parameterize it and turn it into a script. This is especially great if you’re not a hard-core scripter, or if you aren’t very familiar with PowerShell.

image

Hmmph, can’t figure out how to make it connect to the server.  I tried making a script node with this snippet: Get-ViServer (read-host “Server Name”).  No luck.  Will mess more with it later.

April 1st, 2008

PowerShell Version 2 Released!

Powershell

According to the PowerShell Team Blog, Jeffrey Snover has announced the surprise release of PowerShell Version 2.  New features include:

  • Remoting - this is the ability to execute powershell statements on remote computers
  • Script Cmdlets - you can now make real cmdlets using only powershell script–no C# required!
  • Tons of new cmdlets for controlling popular web-services such as:
  • Out-Flickr
  • Get-OrkutProfile
  • Post-DelIcioUsBookmark
  • Find-Yahoo
  • Out-Digg
  • They finally fixed the WMI authentication bugs!
  • Now I find the most intriguing aspect of the new cmdlets is that it shows a strange confluence of Microsoft and Yahoo technologies.  Did MSFT play their hand too early?  I wonder if this means more than it appears…Watch the two stock prices today.

    Go download it now!  Here’s a screencast I did of the new stuff in action.

    March 24th, 2008

    PowerShell Haiku: How to Use Here Strings

    Powershell

       1: # My first PowerShell haiku
       2: $herestring = @”
       3: This is the best way
       4: when you want to span across
       5: multiple lines, dude.
       6: “@

    Hope this helps. :)

    March 24th, 2008

    Consistent Command-Line Interface: One More Reason to Like PowerShell

    Powershell

    I just have trouble believing that a currently developed OS (NetBSD for the record) still has this kind of opaqueness. This is a problem I will never have again when working in PowerShell!

    image

    On PowerShell all cmdlets have built-in help which can be accessed a variety of ways, the simplest of which is:

    cmdlet-name -?

    The more verbose versions include “help <cmdlet-name>”, and “get-help <cmdlet-name>” with increasingly higher levels of detail obtained by supplying parameters to Get-Help such as “-example”, “-detailed”, and “full”.

    March 18th, 2008

    PowerShell Tip: Line Continuation Characters

    Powershell

    Line continuation (and termination for that matter) characters are not required that often.

    • An open brace { , parenthesis ( , or square bracket [ will allow for continuation across multiple lines until the block is closed by the corresponding } ) ]
    • A trailing comma (the array operator) will allow for a line break until the next array member
    • Single and double-quotes will work as well, but I really don’t recommend doing so just because its unexpected and confusing to read the code. If you want to do this, instead use the “here string” feature and enclose your multi-line string with @” and “@

    So you can do this without a single line-continuation character (a trailing back-tick ` )

    function test {
      param (
        $firstname,
        $lastname
      )
      (get-process) [
        1
      ]
      write-host "$firstname
    $lastname" # don't do this, or kittens will die
    }

    March 15th, 2008

    VMware PowerShell Toolkit Open Beta

    Powershell

    At long last, VMware has released their PowerShell toolkit to the public.  You can grab it at this convenient URL (love it when companies do that):

    http://vmware.com/go/powershell

    There is already an official forum online for the toolkit which those in the closed beta were already participating.  That means there’s already some content in there for new users.  It’s a great place to ask questions. 

    The toolkit is still beta, and the documentation is unfinished.  But what’s in there now is really cool and very stable.  I believe it is covered by VMware Support already so you can actually open a support case if you run into trouble, if you have a support contract.  Below is a list of the scope of the cmdlets included.  Instead of waste 102 lines of text I’ve grouped them by verb and noun for clarity.

       1: 76# Get-Command -PSSnapin v* | group verb | ft count,name -auto
       2:  
       3: Count Name
       4: —– —-
       5:     1 Add
       6:     1 Dismount
       7:     2 Find
       8:    28 Get
       9:     1 Load
      10:     1 Mount
      11:     7 Move
      12:    16 New
      13:    17 Remove
      14:     1 Restart
      15:     1 Save
      16:    18 Set
      17:     1 Shutdown
      18:     1 Start
      19:     2 Stop
      20:     2 Suspend
      21:     1 Update
      22:     1 Wait
      23:  
      24: 77# Get-Command -PSSnapin v* | group noun | ft count,name -auto
      25:  
      26: Count Name
      27: —– —-
      28:     5 VMHost
      29:     3 Tools
      30:     1 EntityView
      31:     1 EntityViews
      32:     4 CDDrive
      33:     5 Cluster
      34:     5 Datacenter
      35:     4 Datastore
      36:     1 Event
      37:     4 FloppyDrive
      38:     5 Folder
      39:     3 HardDisk
      40:     3 Inventory
      41:     1 Log
      42:     1 LogType
      43:     4 NetworkAdapter
      44:     4 OSCustomizationSpec
      45:     5 ResourcePool
      46:     4 Snapshot
      47:     1 Stat
      48:     3 Task
      49:     4 Template
      50:     1 View
      51:     1 Views
      52:     4 VirtualSwitch
      53:     1 VIServer
      54:     1 VIToolkitVersion
      55:     8 VM
      56:     4 VMGuest
      57:     2 VMHostNetwork
      58:     1 VMHostStorage
      59:     2 Session
      60:     3 CustomField
      61:     3 VMHostNetworkAdapter

    Supposedly there was going to be a PSDrive provider as well but I don’t see it anywhere.  Maybe it’ll turn up.  :)

    March 14th, 2008

    So, I’m Writing A Book

    Powershell

    No, seriously!  I’ve never written anything longer than a lengthy blog post or maybe a two-page email.  Now’s my chance to shatter that record.  Anybody who knows me has heard me say before that I have zero creativity.  Luckily, that’s not required when writing a technical manual.  :D  We’ll see how it goes. 

    Anyway, the book is to be published by Sapien Press.  I’m not saying when the book will be ready at this point because I have no clue how these things work.  I guess it is safe to say, “this year”.  Hopefully, well inside of that time period.  :)

    If you read my blog, you probably know my current passions are PowerShell and VMware.  Well, it should come as no surprise that the working book title is: Managing VMware Infrastructure with PowerShell: TFM.  I’m really excited about the project and I hope it turns out well.  And if nothing else it’ll be good fuel for a fire.  Win-win for everyone!

    Wish me luck, and may God grant my wife patience!

    March 3rd, 2008

    Server 2008 & PowerShell discussion, continued

    Powershell Windows

    My long reply to a long reply was getting a bit…long, so I thought I’d move it here. Much easier to do the editing in Live Writer anyhow. :)

    You can find the original article and several comments from myself and the author at this blog post: Why PowerShell, Servermanagercmd and co. don’t really rock on the command prompt. I recommend you read the article, it’s a nicely-worded opinion piece. The article deals with the author’s frustrations with Server 2008 command-line utilities (which I agree with) but he then extends those opinions on to PowerShell. I’m making the point that PowerShell addresses most if not all of his frustrations. He also goes into reasons why he thinks the GUI is generally superior for any task, which I also disagree with. (Lots of dangling prepositions today.)

    My reply continues below:

    Well, the PowerShell rebuttal to ‘difficulty in memorizing commands’ is handled by a cmdlet called “get-command”, and the enforced (by Microsoft’s Common Engineering Criteria internally) consistent naming convention for cmdlets and other related interfaces such as PS Providers. For example, say you want to do something with a mailbox in exchange. You already know the noun you are dealing with–it’s a mailbox. So you type “get-command *mailbox” or “get-command -noun mailbox” and you’ll get several matches. To go a step higher, say you know you want to do something with VMware but you forgot how to connect to the auth server and you have no idea if the verb (the part before the dash) is even called ‘connect’. In a case like that you would use “get-command -pssnapin v*”. That will return all cmdlets which are contained within any snapin which starts with the letter V.

    On top of all that, there’s some great IDEs and enhanced editors and graphical consoles whicih make all of this even easier. You can tet real visual studio-like Intellisense on filenames, cmdlets, parameters, .NET types, WMI classes…I certainly can’t memorize every WMI class, but I can type “get-wmiobject win32_net” and hit TAB and voila, there’s a dozen answers popped up in a listbox.

    In answer to your point that “The number of software vendors offering tools for administrators has been growing dramatically in the last years.”: I would say YES–and PowerShell is/will be largely seen as responsible for accelerating that trend. VMware, Citrix, IBM and many more vendors are starting to provide PowerShell hooks.

    And lastly, of course GUIs are more prone to mistake! How many times have people accidentally clicked on shutdown when they meant logoff (before the start menu was rearranged in what…2003)? I mean…seriously, I could go on and on. GUI accidents could be blamed for spyware installs, too.

    If I’m about to make a change in a production environment which may have adverse affects, best practice wisdom would say (yeah, I know that’s like saying “they say” but hear me out) you should make a change plan and a backout plan. You are already doing things to a high level of detail, you might as well script the whole thing. This allows you to not only automate the change, but to validate the change, and if necessary, reverse it. This applies doubly so if you are not the person to make the change. Maybe you are the lead admin delegating a task off to a junior admin or an offshore resource. you tell them:

    Run this script, wake me if stuff starts blowing up!

    March 3rd, 2008

    PowerScripting Podcast Episode 20

    Powershell

    Head over to powerscripting.net to listen to our latest episode.  This week’s show:

    • News: Don Jones’ technet column, Sapien’s doing training, and Jeffrey snover will be an upcoming guest
    • Resources: RunAs Radio interviews Marco Shaw, SDM Software updates their freeware group policy management cmdlets, Spec Ops posts a video, also about group policy, and a new free e-Book from Swiss IT Pro Frank Koch.
    • Tips: custom object types & formatting, Get-Qaduser advanced filtering, using AutoItx from Powershell, and the difficulties of deploying WinRM and other software out to an enterprise full of servers.
    • And more!
    Close
    E-mail It