Skip to content

Instantly share code, notes, and snippets.

View bielawb's full-sized avatar

Bartek Bielawski bielawb

View GitHub Profile
$xml = [XML](Get-Content .\Test.xml)
$xml.root.node[0].subNode
Select-Xml -Path .\TestPage.xhtml -XPath //h1 |
ForEach-Object { $_.Node } | Format-Table -AutoSize InnerText, ParentNode
Select-Xml -Path .\TestPage.xhtml -XPath "//h1[@id = 'title']"
Select-Xml -Path .\TestPage.xhtml -XPath "//x:h1[@id = 'title']" -Namespace @{
x = 'http://www.w3.org/1999/xhtml'
} | ForEach-Object { $_.Node } | Format-Table -AutoSize
$addressUp = @'
//host/address[
@addrtype = 'ipv4' and
../status/@state = 'up'
]
'@
$nodeList = Select-Xml -Path .\testLocal.xml -XPath $addressUp |
ForEach-Object { $_.Node }
Select-Xml -Path .\Test.xml -XPath "//subNode[@Number > 1]" |
ForEach-Object { $_.Node }
Select-Xml -Path .\TestPage.xhtml -XPath "//*[contains(@id,'test')]" |
ForEach-Object { $_.Node }
$xpath = @'
//*[
contains(
name(),
@bielawb
bielawb / DSCDemo.ps1
Created August 31, 2014 09:35
Linux DSC:
configuration LinuxDscDemo {
param (
[string]$ComputerName
)
Import-DscResource -Module nx
Node $ComputerName {
nxUser LinuxDsc {
@bielawb
bielawb / Japanese.ps1
Last active August 29, 2015 14:06
Just a test code for ConvertFrom-String used with Japanese (well.. or so I think) ;)
$Template = @'
{Name*:霧嶋 董香}
{City:Redmond}, {State:WA}
{Name*:Łukasz Ćwikalski}
{City:ワルシャワ}, {State:PL}
'@
$Data = @'
霧嶋 董香
@bielawb
bielawb / Nested-cfs.ps1
Created September 18, 2014 22:08
ConvertFrom-String - nested properties (improved).
$data = @'
=
Adam Nowacki
Domowy:123 456 789
Praca:999 999 999
[prywatny/adam@nowacki.pl]
[sluzbowy/AdamNowacki@firma.pl]
=
Anna Kowalska
Domowy:123 456 789
@bielawb
bielawb / Excel.psm1
Created March 13, 2015 04:31
Module to read Excel as if it was just XML. Needs work (e.g. some cleanup after data is read).
<#
List taken from SO answer:
http://stackoverflow.com/questions/4730152/what-indicates-an-office-open-xml-cell-contains-a-date-time-value
#>
$ExCellStyles = @{
0 = 'General'
1 = '0'
2 = '0.00'
3 = '#,##0'
<#
Assumptions:
-- uses v3 module manifest (RootModule rather than ModuleToProcess)
-- RootModule contains name of the file only
-- Certain pattern can be used to check only functions that follow naming convention (here: *-Cim*)
Also:
-- Actual tests include more actions related to manifest contents, thus "context" block is used
-- Actual test is testing multiple modules/ manifests, thus $manifest in the real scenario is part of foreach ($manifest in ls) {}
#>
@bielawb
bielawb / XmlDemo.ps1
Created April 23, 2016 17:38
Demo code from PSConfEU presentation "XML is your friend"
#region Basics...
# implicit foreach on Adapted Type System object.
$xml = [xml]@'
<node attribute="attributeValue">
<CaseSensitive>First</CaseSensitive>
<caseSensitive>second</caseSensitive>
</node>
'@
$PSDefaultParameterValues.'Select-Xml:Xml' = $xml