none
Powershell DPM script from command line is inconsistent RRS feed

  • Question

  • I have a simple Powershell DPM script for listing replica info :-

    foreach ($ds in Get-Datasource -DPMServerName MYDPM | ? {$_.Protected})
    {
        [string]$ds
        $ds.get_ReplicaSize()
        $ds.get_ReplicaUsedSpace()
        $ds.get_LatestRecoveryPoint()
    }

    Inside a DPM Management Shell console, this shows results expected on both a W2003/DPM2007 and an x64/W2008/DPM2010 platform.

    When I run from inside a cmd.exe console or desktop shortcut, using the same command which starts up the DPM Management console, but adding -Command "c:\list.ps1", it works as expected on the W2003/DPM2007 platform.

    But in the x64/W2008/DPM2010 case, the dates returned for get_LatestRecoveryPoint() are 01 January 0001 00:00:00 (obviously 0/NULL) but the other values are correct!

    When I use instead -Command "C:\list.ps1 ; c:\list.ps1", the second listing shows the correct dates. Weird or what?

    On the x64/W2008/DPM2010, the command line is:-

    C:\Windows\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile "C:\Program Files\Microsoft DPM\DPM\bin\dpmshell.psc1" -Command  "C:\List.ps1"

    Originally I was running this command line from a C application and found this problem with the dates. But it seems to happen even if the command is typed into a cmd.exe console, or from a desktop shortcut.

    Any suggestions would be much appreciated,

    thanks

    James

     

     

     

    • Moved by MarcReynolds Friday, May 20, 2011 3:12 PM (From:Data Protection Manager)
    Monday, October 11, 2010 5:19 PM

Answers

All replies

  • HI James,

     

    Yes, That is a know timing issue, running it twice usually returns accurate results.  Not sure what the final fix is going to be or when, so try to work around the issue best you can.


    Regards, Mike J. [MSFT] This posting is provided "AS IS" with no warranties, and confers no rights.
    Monday, October 11, 2010 11:52 PM
    Moderator
  • This annoyed the heck out of me when I first started experimenting with DPM 2010.  Yes, running the command twice usually provides the correct information, but the more complete answer is here:

    http://blogs.technet.com/b/dpm/archive/2010/09/11/why-good-scripts-may-start-to-fail-on-you-for-instance-with-timestamps-like-01-01-0001-00-00-00.aspx

    Basically some attributes are now gathered asynchronously and the values aren't ready until a little bit later.  Unfortunately this does complicate scripts a bit, but if you follow the instructions it works correctly.

    Tuesday, October 12, 2010 4:52 AM
  • Thanks all for the help,

    It looked to me like a threads/serialization issue, but I couldn't see how/why.

    I am new to Powershell, it is deeper than it looks. Thought it was a text-processor to start with!

    When you query an object value, it may still be waiting to be filled in, by the look of it.

    James

     

    Tuesday, October 12, 2010 8:23 AM
  • Yep, that's the gist of it.  For some reason they decided to make the lookup of certain attributes an asynchronous operation in DPM 2010.

    When you check those certain values, Powershell does not pause, gather the information, and return to the next line in the script only once the information has been collected.  The script goes on immediately.  So if you are printing or setting variables right there, you will see zero'd values.

    If you are new to Powershell I can definitely understand why the workaround for this seems a bit daunting.  Personally I wish they had never made this change. It worked fine as it was in 2007!

    Tuesday, October 12, 2010 1:25 PM