#1 07 Dec 2011 11:26

jumper
Member
From: tunisia, Mornaguia
Registered: 17 Apr 2009
Posts: 55
Website

une fonction pour ss64

hi

a small gift for members of SS64 smile

Function Get-ss64 {

<#
 .Example
  PS[1]> Get-ss64

DateTime               Author                 Title                  State                
--------               ------                 -----                  -----                
07/12/2011 05:21:02    theretard              merge                  Offline              
07/12/2011 05:17:36    theretard              FORFILES help          Offline              
06/12/2011 15:06:22    theretard              avoiding loop          Offline              
06/12/2011 03:05:54    theretard              %CommonProgramFiles... Offline              
05/12/2011 20:02:05    theretard              get file location t... Offline              
      
...
...

.Example
 PS[2]> Get-ss64 -Today
 
DateTime               Author                 Title                  State                
--------               ------                 -----                  -----                
07/12/2011 05:21:02    theretard              merge                  Offline              
07/12/2011 05:17:36    theretard              FORFILES help          Offline             


.Example
 PS[3]> get-ss64 | Where { $_.Author -eq 'jumper' } | select Title,DateTime 
 
.Example
 PS[4]> get-ss64 | Where { $_.state -eq 'Online' }

.INPUTS
none

.OUTPUTS
PSCUSTOMOBJECT

#>
 param([Switch]$Today)
 End{
  try{
    $objTable = @()
    $objweb = New-Object net.webclient
    [Xml]$objXml = $objweb.DownloadString('http://ss64.org/extern.php?action=feed&type=atom')
     $objTable += $objXml.feed.entry | Select-Object -Property @{
          Name = 'DateTime'
          Expression = { $_.updated -as [datetime] }
       },@{
          Name = 'Author'
          Expression = { $_ | select -expand author | % { $_.name.'#cdata-section' } }
       },@{
          Name = 'Title'
          Expression = { $_ | select -expand FirstChild | % { $_.'#cdata-section' } }
      },@{
         Name = 'State'
         Expression = { 
           $objlink = New-Object net.webclient
           $link = $_ | select -Expand link | select -Expand href
           $page = $objlink.DownloadString($link)
           $Matches.Clear()
           $prst = $page -match 'offline|Online'
           $Matches[0]
           $objlink.Dispose()
           Remove-Variable objlink
         }
      }
    }
  catch [System.Net.WebException] { return $_.exception.message }
  finally{ 
   $objweb.Dispose()
   if($Today) { 
     $objTable | % { $_.DateTime -eq (date)  }
    } else { $objTable } 
  }
 }
}

Offline

#2 07 Dec 2011 11:44

jumper
Member
From: tunisia, Mornaguia
Registered: 17 Apr 2009
Posts: 55
Website

Re: une fonction pour ss64

tipo

Function Get-ss64 {

<#
 .Example
  PS[1]> Get-ss64

DateTime               Author                 Title                  Online                
--------               ------                 -----                  -----                
07/12/2011 05:21:02    theretard              merge                  True              
07/12/2011 05:17:36    theretard              FORFILES help          False              
06/12/2011 15:06:22    theretard              avoiding loop          False              
06/12/2011 03:05:54    theretard              %CommonProgramFiles... False              
05/12/2011 20:02:05    theretard              get file location t... False              
      
...
...

.Example
 PS[2]> Get-ss64 -Today
 
DateTime               Author                 Title                  Online                
--------               ------                 -----                  -----                
07/12/2011 05:21:02    theretard              merge                  False              
07/12/2011 05:17:36    theretard              FORFILES help          False             


.Example
 PS[3]> get-ss64 | Where { $_.Author -eq 'jumper' } | select Title,DateTime 
 
.Example
 PS[4]> get-ss64 | Where { $_.state -eq 'Online' }

.Example
 PS[5]> get-ss64 | Select -first 3

.INPUTS
none

.OUTPUTS
PSCUSTOMOBJECT

#>
 param([Switch]$Today)
 End{
  try{
    $objTable = @()
    $objweb = New-Object net.webclient
    [Xml]$objXml = $objweb.DownloadString('http://ss64.org/extern.php?action=feed&type=atom')
     $objTable += $objXml.feed.entry | Select-Object -Property @{
          Name = 'DateTime'
          Expression = { $_.updated -as [datetime] }
       },@{
          Name = 'Author'
          Expression = { $_ | select -expand author | % { $_.name.'#cdata-section' } }
       },@{
          Name = 'Title'
          Expression = { $_ | select -expand FirstChild | % { $_.'#cdata-section' } }
      },@{
         Name = 'Online'
         Expression = { 
           $page = ''
           $objlink = New-Object net.webclient
           $link = $_ | select -Expand link | select -Expand href
           $page = $objlink.DownloadString($link)
           $page -match 'online'
           $objlink.Dispose()
           Remove-Variable objlink
         }
      }
    }
  catch [System.Net.WebException] { return $_.exception.message }
  finally{ 
   $objweb.Dispose()
   if($Today) { 
     $objTable | % { $_.DateTime -eq (date)  }
    } else { $objTable } 
  }
 }
}

Offline

#3 07 Dec 2011 18:22

jumper
Member
From: tunisia, Mornaguia
Registered: 17 Apr 2009
Posts: 55
Website

Re: une fonction pour ss64

Function Get-ss64 {

<#
 .Example
  PS[1]> Get-ss64

DateTime               Author                 Title                  Online               
--------               ------                 -----                  -----                
07/12/2011 05:21:02    theretard              merge                  True              
07/12/2011 05:17:36    theretard              FORFILES help          False              
06/12/2011 15:06:22    theretard              avoiding loop          False              
06/12/2011 03:05:54    theretard              %CommonProgramFiles... False              
05/12/2011 20:02:05    theretard              get file location t... False              
      
...
...

.Example
 PS[2]> Get-ss64 -Today
 
DateTime               Author                 Title                  Online               
--------               ------                 -----                  -----                
07/12/2011 05:21:02    theretard              merge                  False              
07/12/2011 05:17:36    theretard              FORFILES help          False             


.Example
 PS[3]> get-ss64 | Where { $_.Author -eq 'user' } | select Title,DateTime 
 
.Example
 PS[4]> get-ss64 -invoke
 # open browser

.Example
 PS[5]> get-ss64 | Select -first 3

.INPUTS
none

.OUTPUTS
PSCUSTOMOBJECT

#>
 param([Switch]$Today,[Switch]$Invoke)
 End{
  try{
    $objTable = @()
    $objweb = New-Object net.webclient
    [Xml]$objXml = $objweb.DownloadString('http://ss64.org/extern.php?action=feed&type=atom')
     $objTable += $objXml.feed.entry | Select-Object -Property @{
          Name = 'DateTime'
          Expression = { $_.updated -as [datetime] }
       },@{
          Name = 'Author'
          Expression = { $_ | select -expand author | % { $_.name.'#cdata-section' } }
       },@{
          Name = 'Title'
          Expression = { $_ | select -expand FirstChild | % { $_.'#cdata-section' } }
      },@{
         Name = 'Online'
         Expression = { 
           $page = ''
           $objlink = New-Object net.webclient
           $link = $_ | select -Expand link | select -Expand href
           $page = $objlink.DownloadString($link)
           $page -match 'online'
           $objlink.Dispose()
           Remove-Variable objlink
         }
      }
      if($Today) { 
        $objTable | Where { $_.DateTime -eq (date)  }
      } else { $objTable }
      if($Invoke) {
        start $($objXml.feed.entry | select -expand link | % { $_.href })[0]
      } 
    }
  catch [System.Net.WebException] { return $_.exception.message }
  finally{ 
   $objweb.Dispose()
   }
 }
}

Offline

#4 07 Dec 2011 21:46

theretard
Member
Registered: 01 Mar 2011
Posts: 33

Re: une fonction pour ss64

so how do you make powershell post the post here for you?

Offline

#5 09 Dec 2011 06:48

jumper
Member
From: tunisia, Mornaguia
Registered: 17 Apr 2009
Posts: 55
Website

Re: une fonction pour ss64

I made mistakes in the first two code

Offline

#6 14 Nov 2012 20:25

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 899
Website

Re: une fonction pour ss64

theretard wrote:

so how do you make powershell post the post here for you?

You need to scroll within the posts above to see all the code.

Offline

Board footer

Powered by FluxBB