ScanForSpecificUpdate.txt

(5 KB) Pobierz
# =============================================================================
# 
# NAME:ScanForSpecificUpdate.ps1
# 
# AUTHOR: Ed Wilson , microsoft
# DATE  : 11/10/2007
# 
# COMMENT: 
# Uses Params to allow modification of script at runtime
# Uses funHelp function to display help
# Uses funLine function to underline output
#
# =============================================================================

param(
      $computer="localhost",
      $update,
      [switch]$all,
      [switch]$security,
      [switch]$whatif,
      [switch]$help,
      [switch]$examples,
      [switch]$min,
      [switch]$full
      ) #end param

# Begin Functions

function funHelp()
{
 $descriptionText= `
@"
 NAME: ScanForSpecificUpdate.ps1
 DESCRIPTION:
 Scans for a specific update, or updates on a local 
 or remote machine. The script will also produce a 
 listing of all updates installed on the machine. The
 script supports prototyping by using the -whatif 
 parameter.

 PARAMETERS: 
 -computer computer upon which to run the command
 -update update number or numbers
 -all lists all updates installed on the machine
 -security lists only security updates
 -whatif Prototypes the command
 -help prints help description and parameters file
 -examples prints only help examples of syntax
 -full prints complete help information
 -min prints minimal help. Modifies -help

"@ #end descriptionText

$examplesText= `
@"

 SYNTAX:
 ScanForSpecificUpdate.ps1 

 Displays an error missing parameter, and calls help

 ScanForSpecificUpdate.ps1  -computer "Berlin" -all

 Creates a list of all installed updates on a remote 
 computer named Berlin 

 ScanForSpecificUpdate.ps1  -security

 Creates a list of all installed security updates on the
 local machine
 
 ScanForSpecificUpdate.ps1  -update kb945008, KB943078

 Creates a list of installed updates on the local machine
 that match update ID's kb945008, KB943078. If the update
 has not been installed nothing is returned

 ScanForSpecificUpdate.ps1 -update kb945008, KB943078 -whatif
 
 Displays what if: Perform operation query for updates kb945008, KB943078
 on localhost

 ScanForSpecificUpdate.ps1 -help

 Prints the help topic for the script

 ScanForSpecificUpdate.ps1 -help -full

 Prints full help topic for the script

 ScanForSpecificUpdate.ps1 -help -examples

 Prints only the examples for the script

 ScanForSpecificUpdate.ps1 -examples

 Prints only the examples for the script
"@ #end examplesText

$remarks = `
"
REMARKS
     For more information, type: $($MyInvocation.ScriptName) -help -full
" #end remarks

  if($examples) { $examplesText ; $remarks ; exit }
  if($full)     { $descriptionText; $examplesText ; exit } 
  if($min)      { $descriptionText ; exit }
  $descriptionText; $remarks 
  exit
} #end funHelp function

function funline (
                  $strIN,
                  $char = "=",
                  $sColor = "Yellow",
                  $uColor = "darkYellow",
                  [switch]$help
                 )
{
 if($help)
  {
    $local:helpText = `
@"
     Funline accepts inputs: -strIN for input string and -char for seperator
     -sColor for the string color, and -uColor for the underline color. Only 
     the -strIn is required. The others have the following default values:
     -char: =, -sColor: Yellow, -uColor: darkYellow
     Example:
     funline -strIN "Hello world"
     funline -strIn "Morgen welt" -char "-" -sColor "blue" -uColor "yellow"
     funline -help
"@
   $local:helpText
   break
  } #end funline help
  
 $strLine= $char * $strIn.length
 Write-Host -ForegroundColor $sColor $strIN 
 Write-Host -ForegroundColor $uColor $strLine
} #end funLine function

Function funWhatIf()
{
 if($update)
  {
   "what if: Perform operation query for updates $update on $computer"
  }
 if($all)
  {
   "what if: Perform operation query for all updates on $computer"
  }
 if($security)
  {
   "what if: Perform operation query for security updates on $computer"
  }
 exit
} #end funWhatIf

Function funUpdate()
{
 foreach($sUpdate in $update)
  {
   Get-wmiobject -class win32_quickFixEngineering -computername $computer `
   -filter "hotFixID = ""$supdate""" |
   format-table -property HotFixID, InstalledBy, Description
  }
  exit
} #end funUpdate

Function funALL()
{
 Get-wmiobject -class win32_quickFixEngineering -computername $computer |
 sort-object -property HotFixID |
 format-table -property HotFixID, InstalledBy, Description
 exit
} #end funAll

Function funSec()
{
 Get-wmiobject -class win32_quickFixEngineering -computername $computer `
 -filter "Description like '%security%'" |
 sort-object -property HotFixID |
 format-table -property HotFixID, InstalledBy, Description
 exit
} #end funSec


# Entry Point

if($help)      { funhelp }
if($examples)  { funhelp }
if($full)      { funhelp }
if($whatif)    { funWhatIf }
if($update)    { funUpdate }
if($all)       { funall }
if($security)   { funsec }
if(!$update -or !$all -or !$security) { "missing parameter ..." ; funhelp }
Zgłoś jeśli naruszono regulamin