Windows Vista Forums

Info: Write-Progress... any GOOD examples of this?
  1. #1


    Brandon Shell Guest

    Info: Write-Progress... any GOOD examples of this?

    Im looking for practical applications of this. Any caveats?





      My System SpecsSystem Spec

  2. #2


    =?Utf-8?B?Um9tYW4gS3V6bWlu?= Guest

    RE: Info: Write-Progress... any GOOD examples of this?

    I did not see caveats yet. What do you mean 'GOOD' example? Is this one good?

    for($i = 1; $i -le 100; $i++ )
    {
    write-progress Updating progress -perc $i;
    for($j = 1; $j -le 100; $j++ )
    {
    write-progress Secondary progress -perc $j -id 1; sleep -m 10
    }
    }

    --
    Thanks,
    Roman


      My System SpecsSystem Spec

  3. #3


    =?Utf-8?B?U3VuZyBNIEtpbQ==?= Guest

    RE: Info: Write-Progress... any GOOD examples of this?

    If you go to Mow's tab completion
    blogentry(http://mow001.blogspot.com/2006/06/p...on-part-4.html)
    , "TabExpansion" function uses "write-progress" while caching type
    information.


    And
    "http://img.photobucket.com/albums/v138/dance2die/powershell/progressbar.jpg"
    that is how it displays(it will display a bit different when you use Mow's
    tab completion function, no type name information will be displays but only
    progress bars)

    Two progressbars display how much of type caching has been performed...

    --
    Sung M Kim

    Please don''t bother me with spam...


    "Brandon Shell" wrote:

    > Im looking for practical applications of this. Any caveats?
    >
    >
    >


      My System SpecsSystem Spec

  4. #4


    Brandon Shell Guest

    Re: Info: Write-Progress... any GOOD examples of this?

    Thanks.

    "Sung M Kim" <SungMKim@discussions.microsoft.com> wrote in message
    news:1614D914-41C8-4D89-83B1-6983C3AFBF15@microsoft.com...
    > If you go to Mow's tab completion
    > blogentry(http://mow001.blogspot.com/2006/06/p...on-part-4.html)
    > , "TabExpansion" function uses "write-progress" while caching type
    > information.
    >
    >
    > And
    > "http://img.photobucket.com/albums/v138/dance2die/powershell/progressbar.jpg"
    > that is how it displays(it will display a bit different when you use Mow's
    > tab completion function, no type name information will be displays but
    > only
    > progress bars)
    >
    > Two progressbars display how much of type caching has been performed...
    >
    > --
    > Sung M Kim
    >
    > Please don''t bother me with spam...
    >
    >
    > "Brandon Shell" wrote:
    >
    >> Im looking for practical applications of this. Any caveats?
    >>
    >>
    >>




      My System SpecsSystem Spec

  5. #5


    James Truher Guest

    Re: Write-Progress... any GOOD examples of this?

    here are a couple:
    the first is a basic view of progress - it's kind of cute:

    $r = new-object system.random
    for ( $perc = 0 ; $perc -le 100; $perc += ( $r.next(1,10)) )
    {
    foreach ( $id in 01,02,03 )
    #,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20 )
    {
    write-progress ("Activity: {0,2}" -f $id) "Active $id" $id -perc
    $perc
    start-sleep -mi 100
    }
    write-progress "SubActivity: 12" "Active 12" 21 -perc $perc -parentid 12
    start-sleep -mi 100
    }
    write-progress "SubActivity: 12 - now sleeping for 3 seconds" "Active 12"
    21 -perc 100 -parentid 12
    start-sleep 3

    This next script gets all the methods from all the types in the current
    process and returns a big honking hash table - it shows another way to use
    progress:

    # Get-Methods.sp1
    $hash = @{}
    $asms = [appdomain]::currentdomain.getassemblies()
    $asms | foreach { $cur = 1 } {
    trap { continue }
    $perc = [int](( $cur / $asms.count ) * 100)
    $name = $_.getname().name
    write-progress "Getting Types from $name" Active 0 -perc $perc
    $_.gettypes() # push the types down the pipeline
    $cur++
    } |
    foreach {
    trap { continue }
    $name = $_.fullname
    $hash.$name = $_.GetMethods()
    }
    $hash

    PS> $hash = Get-Methods
    PS> $hash."System.Object"|%{"$_"}
    System.Type GetType()
    Int32 GetHashCode()
    System.String ToString()
    Boolean Equals(System.Object)
    Boolean Equals(System.Object, System.Object)
    Boolean ReferenceEquals(System.Object, System.Object)





    --
    James Truher[MSFT]
    Program Manager - Windows PowerShell
    Microsoft Corporation
    This posting is provided "AS IS" with no warranties, no confers rights.
    Visit the Windows PowerShell Team blog at:
    http://blogs.msdn.com/PowerShell
    Visit the Windows PowerShell ScriptCenter at:
    http://www.microsoft.com/technet/scr.../hubs/msh.mspx
    "Brandon Shell" <tshell.mask@gmail.com> wrote in message
    news:eKrgd15xGHA.3464@TK2MSFTNGP03.phx.gbl...
    > Im looking for practical applications of this. Any caveats?
    >




      My System SpecsSystem Spec

  6. #6


    Brandon Shell Guest

    Re: Write-Progress... any GOOD examples of this?

    Thanks James... Im just trying to wrap my mind around this concept. I think
    your example helped.

    "James Truher" <jimtru@news.microsoft.com> wrote in message
    news:OfGmHbsyGHA.4452@TK2MSFTNGP05.phx.gbl...
    > here are a couple:
    > the first is a basic view of progress - it's kind of cute:
    >
    > $r = new-object system.random
    > for ( $perc = 0 ; $perc -le 100; $perc += ( $r.next(1,10)) )
    > {
    > foreach ( $id in 01,02,03 )
    > #,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20 )
    > {
    > write-progress ("Activity: {0,2}" -f $id) "Active $id" $id -perc
    > $perc
    > start-sleep -mi 100
    > }
    > write-progress "SubActivity: 12" "Active 12" 21 -perc $perc -parentid
    > 12
    > start-sleep -mi 100
    > }
    > write-progress "SubActivity: 12 - now sleeping for 3 seconds" "Active 12"
    > 21 -perc 100 -parentid 12
    > start-sleep 3
    >
    > This next script gets all the methods from all the types in the current
    > process and returns a big honking hash table - it shows another way to use
    > progress:
    >
    > # Get-Methods.sp1
    > $hash = @{}
    > $asms = [appdomain]::currentdomain.getassemblies()
    > $asms | foreach { $cur = 1 } {
    > trap { continue }
    > $perc = [int](( $cur / $asms.count ) * 100)
    > $name = $_.getname().name
    > write-progress "Getting Types from $name" Active 0 -perc $perc
    > $_.gettypes() # push the types down the pipeline
    > $cur++
    > } |
    > foreach {
    > trap { continue }
    > $name = $_.fullname
    > $hash.$name = $_.GetMethods()
    > }
    > $hash
    >
    > PS> $hash = Get-Methods
    > PS> $hash."System.Object"|%{"$_"}
    > System.Type GetType()
    > Int32 GetHashCode()
    > System.String ToString()
    > Boolean Equals(System.Object)
    > Boolean Equals(System.Object, System.Object)
    > Boolean ReferenceEquals(System.Object, System.Object)
    >
    >
    >
    >
    >
    > --
    > James Truher[MSFT]
    > Program Manager - Windows PowerShell
    > Microsoft Corporation
    > This posting is provided "AS IS" with no warranties, no confers rights.
    > Visit the Windows PowerShell Team blog at:
    > http://blogs.msdn.com/PowerShell
    > Visit the Windows PowerShell ScriptCenter at:
    > http://www.microsoft.com/technet/scr.../hubs/msh.mspx
    > "Brandon Shell" <tshell.mask@gmail.com> wrote in message
    > news:eKrgd15xGHA.3464@TK2MSFTNGP03.phx.gbl...
    >> Im looking for practical applications of this. Any caveats?
    >>

    >
    >




      My System SpecsSystem Spec

  7. #7


    =?Utf-8?B?ZHJlZXNjaGtpbmQ=?= Guest

    Re: Write-Progress... any GOOD examples of this?

    The second example also gives us very interesting statistics on the 'power'
    that is included in PowerShell... ;-)

    PS> $hash.count
    10080

    PS> $hash.keys | %{$c = 0} {$hash[$_] | %{$c++} } {"count: $c"}
    count: 175367

    PS> 175367 / 10080
    17,3975198412698

    --
    greetings
    dreeschkind

    "James Truher" wrote:

    > here are a couple:
    > the first is a basic view of progress - it's kind of cute:
    >
    > $r = new-object system.random
    > for ( $perc = 0 ; $perc -le 100; $perc += ( $r.next(1,10)) )
    > {
    > foreach ( $id in 01,02,03 )
    > #,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20 )
    > {
    > write-progress ("Activity: {0,2}" -f $id) "Active $id" $id -perc
    > $perc
    > start-sleep -mi 100
    > }
    > write-progress "SubActivity: 12" "Active 12" 21 -perc $perc -parentid 12
    > start-sleep -mi 100
    > }
    > write-progress "SubActivity: 12 - now sleeping for 3 seconds" "Active 12"
    > 21 -perc 100 -parentid 12
    > start-sleep 3
    >
    > This next script gets all the methods from all the types in the current
    > process and returns a big honking hash table - it shows another way to use
    > progress:
    >
    > # Get-Methods.sp1
    > $hash = @{}
    > $asms = [appdomain]::currentdomain.getassemblies()
    > $asms | foreach { $cur = 1 } {
    > trap { continue }
    > $perc = [int](( $cur / $asms.count ) * 100)
    > $name = $_.getname().name
    > write-progress "Getting Types from $name" Active 0 -perc $perc
    > $_.gettypes() # push the types down the pipeline
    > $cur++
    > } |
    > foreach {
    > trap { continue }
    > $name = $_.fullname
    > $hash.$name = $_.GetMethods()
    > }
    > $hash
    >
    > PS> $hash = Get-Methods
    > PS> $hash."System.Object"|%{"$_"}
    > System.Type GetType()
    > Int32 GetHashCode()
    > System.String ToString()
    > Boolean Equals(System.Object)
    > Boolean Equals(System.Object, System.Object)
    > Boolean ReferenceEquals(System.Object, System.Object)
    >
    >
    >
    >
    >
    > --
    > James Truher[MSFT]
    > Program Manager - Windows PowerShell
    > Microsoft Corporation
    > This posting is provided "AS IS" with no warranties, no confers rights.
    > Visit the Windows PowerShell Team blog at:
    > http://blogs.msdn.com/PowerShell
    > Visit the Windows PowerShell ScriptCenter at:
    > http://www.microsoft.com/technet/scr.../hubs/msh.mspx
    > "Brandon Shell" <tshell.mask@gmail.com> wrote in message
    > news:eKrgd15xGHA.3464@TK2MSFTNGP03.phx.gbl...
    > > Im looking for practical applications of this. Any caveats?
    > >

    >
    >
    >


      My System SpecsSystem Spec

Info: Write-Progress... any GOOD examples of this? problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Write-Progress for ONE cmdlet bLumEisoN PowerShell 1 30 Apr 2008
Changing the 'o' character used in Write-Progress? Duncan Smith PowerShell 3 17 Dec 2007
Understanding Write-Progress with in foreach deadmeatdave@gmail.com PowerShell 1 03 Jan 2007
How do I hide the last Write-Progress message? Roman Kuzmin PowerShell 5 11 Oct 2006
Asyncronous Write-Progress Staffan Gustafsson PowerShell 0 05 Jun 2006