PowerShell Data Basics

PowerShell Data Basics: File Based Data

https://www.simple-talk.com/sysadmin/powershell/powershell-data-basics-file-based-data/

PowerShell Data Basics: XML

https://www.simple-talk.com/sysadmin/powershell/powershell-data-basics-xml/
Advertenties

Using Select-Xml With XmlNamespaces

Using Select-Xml With XmlNamespaces

#  Select-XML is a nifty cmdlet included in PowerShell V2,             
#   and it lets you perform xPath queries.            
#  It also makes a pair of scenarios that are             
#   otherwise a little tricky with xpath fairly simple.            
#  Read below, or check out this video             
#   that walks thru Select-XMl and namespaces            
#  Let's look at a quick example.             
#  Here's a sample service definition for Azure:            

$xml=[xml]@"<?xml version="1.0" encoding="utf-16"?>
<ServiceDefinition name="foobar" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
  <WebRole name="WebRole1" enableNativeCodeExecution="true">
    <Sites>
      <Site name="Web1">
        <Bindings>
          <Binding endpointName="DefaultWebSiteEndPoint" name="Binding1" hostHeader="foo.bar.com" />
        </Bindings>
      </Site>
      <Site name="Web2">
        <Bindings>
          <Binding endpointName="DefaultWebSiteEndPoint" name="Binding1" hostHeader="bar.baz.com" />
        </Bindings>
      </Site>
    </Sites>
    <Endpoints>
      <InputEndpoint name="DefaultWebSiteEndPoint" protocol="http" port="80" />
    </Endpoints>
  </WebRole>
</ServiceDefinition>
"@            

#  If I want to find all of the Bindings in this XML with xPath,
#   .NET has some surprises in store.
#  That is: // in Xpath grabs a node at any depth,             
#   but only if you specify a namespace.            

$xml.SelectNodes("//Binding")            # results in nothing!            

#  The .NET code to deal with namespaces is pretty tedious,            
#   and you do not need to know it.            
#  Select-Xml can make it a lot easier with the -Namespace parameter.             
#  -Namespace is a hashtable, and you put a shortname             
#   for the way you want to find the XML.            
#  XMLNS is reserved, so I'll use "Azure"            
#  Using this, it's quick and easy to zoom right in             
#   on the piece of information we're after            

Select-Xml -Xml $xml -Namespace @{                        
    Azure='http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition'                        
} -XPath //Azure:Binding |                        
    Select-Object -ExpandProperty Node |                        
    Select-Object -ExpandProperty HostHeader                            

# And That Works !                

XML to Word

XML to Word

http://richardspowershellblog.wordpress.com/2009/01/30/xml-to-word/

XPath Tutorial

XPath Tutorial

http://richardspowershellblog.wordpress.com/2008/06/29/xpath-tutorial/

Persist Objects, with CliXml

Persist Objects, with CliXml

http://richardspowershellblog.wordpress.com/2008/02/04/clixml/

Exporting and Importing Credentials

Exporting and Importing Credentials

http://powershell.com/cs/blogs/tips/archive/2009/12/08/exporting-and-importing-credentials.aspx

Adding File Age to file objects

Adding File Age to file objects

http://powershell.com/cs/blogs/tips/archive/2009/12/14/adding-file-age-to-file-objects.aspx