共用方式為


Powershell - Export your print configuration from registry

I was asked to produce this script for follow up checking of driver versions later on or possible settings which can cause problems.

 

The idea would be that a master file is updated on a website and then we can reference this in the script to pull it down and process for the latest errors against the print configuration on the server.

 

here is part one of the script..... this will export all your print configuration into a results.txt file which is then easily worked with...

 

the "error" file is being worked on and another blog post will be done to show the extended script....

 

here is the code....

###########################################################################################

#this is the registry key that contains all settings and information regarding printing, dump it into a variable

$registry = ls HKLM:\SYSTEM\CurrentControlSet\Control\Print -Recurse

#Check if the output file exists on the desktop if so delete it

$inputfilepath = $env:USERPROFILE + "\Desktop"
$outputfile = "results.txt"
$fullpath = $inputfilepath + "\" + $outputfile
$fileexist = test-path $fullpath

if ($fileexist -eq $true)
{
 write-host "File Exists ... Deleting..." -foregroundcolor Red -Backgroundcolor Black
 del $fullpath
}

#Process the registry dump into something easier to read....

foreach ($reg in $registry)
{
 $returnobject = new-object psobject
 
 $values = get-itemproperty $reg.pspath

 Write-host "Registry Path :`t`t`t" $reg "`n" -foregroundcolor Yellow -backgroundcolor Black
 
 
 #dumping each reg key into its own object...
 Add-Member -Inputobject $returnobject -Name "Reg Key" -MemberType Noteproperty -value $reg -force

 foreach ($value in $reg.property)
 {
  
  #adding each value of the reg key into the main object....  
  Add-Member -Inputobject $returnobject -Name $value -MemberType Noteproperty -value $values.$value

  
  
 
 }

 #dumping it to the results file
 $returnobject |fl * |out-file $fullpath -append
     

write-host `n`n`n

$returnobject = $null

 

}

cls
write-host "Finished Processing.... Check results.txt for output" -foregroundcolor Green -backgroundcolor Black

 

##################################################################################################3