# encoding: ascii
# api: powershell
# title: Import-GmailFilterXml
# description: Gmail can now import and export filters as XML. This script will read in an XML file generated by Gmail (the Path parameter), and create from it a flat PSObject with Id, Updated, Name and Value fields. Since it is flat, you must use the Id field to correlate the filter criteria and actions. As far as I can tell, the first item in a filter is the criteria, and any subsequent ones describe the action to take. More info about filter import/export can be found here: http://gmailblog.blogspot.com/2009/03/new-in-labs-filter-importexport.html
# version: 0.1
# license: CC0
# x-poshcode-id: 960
# x-archived: 2009-03-29T05:34:20
#
# P.S. Pipe this to Out-GridView (PowerShell v2 only) for a nice display.
# TODO: – script the actual export of filters from gmail, removing need for working with the file at all – display in a treeview to better visualize the multiple items in each entry.
#
param (
$Path
)
[xml]$flt = Get-Content -Path $Path
$title = $flt.feed.title
$author = $flt.feed.author.name
$output = @()
foreach ( $entry in $flt.feed.entry ) {
foreach ( $property in $entry.property ) {
foreach ($item in $property) {
$process = "" | select Id, Updated, Name, Value
$process.Id = $entry.Id
$process.Updated = [datetime]$entry.Updated
$process.Name = $item.Name
$process.Value = $item.Value
$output += $process
}
}
}
$output