Peach fuzzer. Create docx and fuzzing ms-word - fuzzing

By means of such pit-file I can generate [Content_Types].xml
<?xml version="1.0" encoding="utf-8"?>
<Peach xmlns="http://peachfuzzer.com/2012/Peach" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://peachfuzzer.com/2012/Peach ../peach.xsd">
<!-- Define our file format DDL -->
<DataModel name="TestTemplate">
<XmlElement elementName="Types" ns="http://schemas.openxmlformats.org/package/2006/content-types">
<XmlElement elementName="Default">
<XmlAttribute attributeName="Extension">
<String value="png">
<Analyzer class="StringToken"/>
</String>
</XmlAttribute>
<XmlAttribute attributeName="ContentType">
<String value="image/png">
<Analyzer class="StringToken"/>
</String>
</XmlAttribute>
</XmlElement>
<XmlElement elementName="Default">
<XmlAttribute attributeName="Extension">
<String value="emf">
<Analyzer class="StringToken"/>
</String>
</XmlAttribute>
<XmlAttribute attributeName="ContentType">
<String value="image/x-emf">
<Analyzer class="StringToken"/>
</String>
</XmlAttribute>
</XmlElement>
<XmlElement elementName="Default">
<XmlAttribute attributeName="Extension">
<String value="rels">
<Analyzer class="StringToken"/>
</String>
</XmlAttribute>
<XmlAttribute attributeName="ContentType">
<String value="application/vnd.openxmlformats-package.relationships+xml">
<Analyzer class="StringToken"/>
</String>
</XmlAttribute>
</XmlElement>
<XmlElement elementName="Default">
<XmlAttribute attributeName="Extension">
<String value="xml">
<Analyzer class="StringToken"/>
</String>
</XmlAttribute>
<XmlAttribute attributeName="ContentType">
<String value="application/xml">
<Analyzer class="StringToken"/>
</String>
</XmlAttribute>
</XmlElement>
<XmlElement elementName="Default">
<XmlAttribute attributeName="Extension">
<String value="vsdx">
<Analyzer class="StringToken"/>
</String>
</XmlAttribute>
<XmlAttribute attributeName="ContentType">
<String value="application/vnd.ms-visio.drawing">
<Analyzer class="StringToken"/>
</String>
</XmlAttribute>
</XmlElement>
<XmlElement elementName="Default">
<XmlAttribute attributeName="Extension">
<String value="wdp">
<Analyzer class="StringToken"/>
</String>
</XmlAttribute>
<XmlAttribute attributeName="ContentType">
<String value="image/vnd.ms-photo">
<Analyzer class="StringToken"/>
</String>
</XmlAttribute>
</XmlElement>
<XmlElement elementName="Override">
<XmlAttribute attributeName="PartName">
<String value="/word/document.xml">
<Analyzer class="StringToken"/>
</String>
</XmlAttribute>
<XmlAttribute attributeName="ContentType">
<String value="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml">
<Analyzer class="StringToken"/>
</String>
</XmlAttribute>
</XmlElement>
<XmlElement elementName="Override">
<XmlAttribute attributeName="PartName">
<String value="/word/numbering.xml">
<Analyzer class="StringToken"/>
</String>
</XmlAttribute>
<XmlAttribute attributeName="ContentType">
<String value="application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml">
<Analyzer class="StringToken"/>
</String>
</XmlAttribute>
</XmlElement>
<XmlElement elementName="Override">
<XmlAttribute attributeName="PartName">
<String value="/word/styles.xml">
<Analyzer class="StringToken"/>
</String>
</XmlAttribute>
<XmlAttribute attributeName="ContentType">
<String value="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml">
<Analyzer class="StringToken"/>
</String>
</XmlAttribute>
</XmlElement>
<XmlElement elementName="Override">
<XmlAttribute attributeName="PartName">
<String value="/word/settings.xml">
<Analyzer class="StringToken"/>
</String>
</XmlAttribute>
<XmlAttribute attributeName="ContentType">
<String value="application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml">
<Analyzer class="StringToken"/>
</String>
</XmlAttribute>
</XmlElement>
<XmlElement elementName="Override">
<XmlAttribute attributeName="PartName">
<String value="/word/webSettings.xml">
<Analyzer class="StringToken"/>
</String>
</XmlAttribute>
<XmlAttribute attributeName="ContentType">
<String value="application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml">
<Analyzer class="StringToken"/>
</String>
</XmlAttribute>
</XmlElement>
<XmlElement elementName="Override">
<XmlAttribute attributeName="PartName">
<String value="/word/footnotes.xml">
<Analyzer class="StringToken"/>
</String>
</XmlAttribute>
<XmlAttribute attributeName="ContentType">
<String value="application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml">
<Analyzer class="StringToken"/>
</String>
</XmlAttribute>
</XmlElement>
<XmlElement elementName="Override">
<XmlAttribute attributeName="PartName">
<String value="/word/endnotes.xml">
<Analyzer class="StringToken"/>
</String>
</XmlAttribute>
<XmlAttribute attributeName="ContentType">
<String value="application/vnd.openxmlformats-officedocument.wordprocessingml.endnotes+xml">
<Analyzer class="StringToken"/>
</String>
</XmlAttribute>
</XmlElement>
<XmlElement elementName="Override">
<XmlAttribute attributeName="PartName">
<String value="/word/header1.xml">
<Analyzer class="StringToken"/>
</String>
</XmlAttribute>
<XmlAttribute attributeName="ContentType">
<String value="application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml">
<Analyzer class="StringToken"/>
</String>
</XmlAttribute>
</XmlElement>
<XmlElement elementName="Override">
<XmlAttribute attributeName="PartName">
<String value="/word/fontTable.xml">
<Analyzer class="StringToken"/>
</String>
</XmlAttribute>
<XmlAttribute attributeName="ContentType">
<String value="application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml">
<Analyzer class="StringToken"/>
</String>
</XmlAttribute>
</XmlElement>
<XmlElement elementName="Override">
<XmlAttribute attributeName="PartName">
<String value="/word/theme/theme1.xml">
<Analyzer class="StringToken"/>
</String>
</XmlAttribute>
<XmlAttribute attributeName="ContentType">
<String value="application/vnd.openxmlformats-officedocument.theme+xml">
<Analyzer class="StringToken"/>
</String>
</XmlAttribute>
</XmlElement>
<XmlElement elementName="Override">
<XmlAttribute attributeName="PartName">
<String value="/docProps/core.xml">
<Analyzer class="StringToken"/>
</String>
</XmlAttribute>
<XmlAttribute attributeName="ContentType">
<String value="application/vnd.openxmlformats-package.core-properties+xml">
<Analyzer class="StringToken"/>
</String>
</XmlAttribute>
</XmlElement>
<XmlElement elementName="Override">
<XmlAttribute attributeName="PartName">
<String value="/docProps/app.xml">
<Analyzer class="StringToken"/>
</String>
</XmlAttribute>
<XmlAttribute attributeName="ContentType">
<String value="application/vnd.openxmlformats-officedocument.extended-properties+xml">
<Analyzer class="StringToken"/>
</String>
</XmlAttribute>
</XmlElement>
</XmlElement>
</DataModel>
<!-- Define a simple state machine that will write the file and
then launch a program using the FileWriter and DebuggerLaucher publishers -->
<StateModel name="State" initialState="Initial">
<State name="Initial">
<!-- Write out contents of file. The publisher attribute matches
the name we provide for the publisher in the Test section. -->
<Action type="output">
<DataModel ref="TestTemplate" />
</Action>
<!-- Close file -->
<Action type="close" />
<!-- <Action ty -->
<!-- Launch the file consumer -->
<Action type="call" method="ScoobySnacks" publisher="Peach.Agent"/>
</State>
</StateModel>
<!-- Setup a local agent that will monitor for faults -->
<Agent name="LocalAgent">
<!-- <Monitor class="RunCommand">
<Param name="Command" value="ping google.ru" />
</Monitor> -->
<Monitor class="WindowsDebugger">
<Param name="CommandLine" value="C:\Program Files\Sublime Text 3\subl.exe fuzzfile.bin" />
<Param name="WinDbgPath" value="C:\Program Files\Windows Kits\10\Debuggers\x86\" />
<Param name="StartOnCall" value="ScoobySnacks" />
</Monitor>
<!-- Enable heap debugging on our process as well. -->
<Monitor class="PageHeap">
<!-- <Param name="Executable" value="notepad.exe"/> -->
<Param name="Executable" value="C:\Program Files\Sublime Text 3\subl.exe"/>
<Param name="WinDbgPath" value="C:\Program Files\Windows Kits\10\Debuggers\x86\" />
</Monitor>
</Agent>
<Test name="Default">
<Agent ref="LocalAgent" />
<StateModel ref="State"/>
<!-- Configure our publisher with correct filename to write too -->
<Publisher class="File">
<Param name="FileName" value="fuzzfile.bin" />
</Publisher>
<!-- Configure a logger to store collected information -->
<Logger class="Filesystem">
<Param name="Path" value="logtest" />
</Logger>
</Test>
</Peach>
<!-- end -->
By means of such command I can create docx:
C:\peach>"C:\Program Files\7-Zip\7z.exe" a -tzip fuzz.docx _rels\* docProps\* word [Content_Types].xml
How can I create archive from [Content_Types].xml and rest of files using peach and then open it with ms-word?
I need to track(trace) craches of ms-word

I used Monitor class="Process"
<Agent name="LocalAgent">
<Monitor class="Process">
<Param name="Executable" value="C:\Program Files\7-Zip\7z.exe" />
<Param name="Arguments" value="a -tzip myfuzz.docx C:\peach\_rels C:\peach\docProps C:\peach\word [Conntent_Types].xml" />
</Monitor>
........
</Agent>
But for peach v3.1 release it is recommended to use RunCommand

Related

Creating a PowerShell module from files

I have seen this question here but there not working for me.
I currently have taken apart a psm1 file with 200 functions and separated them into individual files.
Functions are separated into public and private functions
\\nasShare\dbasupport\Powershell\Modules\SQLdbatools\SQLdbatools\public
\\nasShare\dbasupport\Powershell\Modules\SQLdbatools\SQLdbatools\private
This is what my new SQLdbatools.psm1 file looks like
#Get public and private function definition files.
$Public = #( Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 -ErrorAction SilentlyContinue )
$Private = #( Get-ChildItem -Path $PSScriptRoot\Private\*.ps1 -ErrorAction SilentlyContinue )
#Dot source the files
Foreach($import in #($Public + $Private))
{
Try
{
. $import.fullname
}
Catch
{
Write-Error -Message "Failed to import function $($import.fullname): $_"
}
}
Export-ModuleMember -Function $Public.Basename
But the Export-ModuleMember gives me an error that command cant be run from psm1 file
Contents of SQLdbatools.ps1xml file
<?xml version="1.0" encoding="utf-8" ?>
<Configuration>
<ViewDefinitions>
<View>
<Name>Default</Name>
<ViewSelectedBy>
<TypeName>SQLdbatools.Question</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader>
<Width>48</Width>
</TableColumnHeader>
<TableColumnHeader>
<Width>12</Width>
</TableColumnHeader>
<TableColumnHeader>
<Width>5</Width>
</TableColumnHeader>
<TableColumnHeader>
<Label>Owner</Label>
<Width>15</Width>
</TableColumnHeader>
<TableColumnHeader>
<Label>Tags</Label>
<Width>20</Width>
</TableColumnHeader>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<Wrap />
<TableColumnItems>
<TableColumnItem>
<PropertyName>Title</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Answer_Count</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Score</PropertyName>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.Owner.display_name</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>($_.Tags | Sort-Object) -Join ', '</ScriptBlock>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>
<View>
<Name>Default</Name>
<ViewSelectedBy>
<TypeName>SQLdbatools.Answer</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader>
<Width>50</Width>
</TableColumnHeader>
<TableColumnHeader>
<Label>Owner</Label>
<Width>20</Width>
</TableColumnHeader>
<TableColumnHeader>
<Width>5</Width>
</TableColumnHeader>
<TableColumnHeader>
<Width>11</Width>
</TableColumnHeader>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<Wrap />
<TableColumnItems>
<TableColumnItem>
<PropertyName>Share_Link</PropertyName>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.Owner.display_name</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Score</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Is_Accepted</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>
</ViewDefinitions>
</Configuration>
contents of my SQLdbatools.psd1 file
#{
# Script module or binary module file associated with this manifest.
RootModule = 'SQLdbatools.psm1'
# Version number of this module.
ModuleVersion = '1.0.0'
# Format files (.ps1xml) to be loaded when importing this module
FormatsToProcess = 'SQLdbatools.Format.ps1xml'
# Functions to export from this module
FunctionsToExport = '*'
# Cmdlets to export from this module
CmdletsToExport = '*'
# Variables to export from this module
VariablesToExport = '*'
# Aliases to export from this module
AliasesToExport = '*'
}
I have ran the SQLdbatools.psm1 without
Export-ModuleMember -Function $Public.Basename
it will not fail but the ps1 files don't load. Is there something wrong in the code or am I not setting this Module up correctly.
Error when trying to import module
Import-Module SQLdbatools
Import-Module : The specified module 'SQLdbatools' was not loaded because no valid module file was found in any module directory.
At line:1 char:1
+ Import-Module SQLdbatools
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (SQLdbatools:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

Windows forms problem - Unable to load Windows.Markup.XamlReader

Please can you help me?
The code makes this output error:
Unable to load Windows.Markup.XamlReader
This code is made by Microsoft Visual Studio - Project WPF APP
[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
[xml]$XAML = #"
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp2"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<Label Name="label1" Content="Label" HorizontalAlignment="Left" Margin="222,102,0,0" VerticalAlignment="Top" Width="92"/>
<Label Name="label2" Content="Label" HorizontalAlignment="Left" Margin="222,177,0,0" VerticalAlignment="Top" Width="92"/>
<Label Name="label3" Content="Label" HorizontalAlignment="Left" Margin="222,246,0,0" VerticalAlignment="Top" Width="92"/>
<TextBox Name="text1" HorizontalAlignment="Left" Margin="369,110,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120" TextChanged="text1_TextChanged_1"/>
<TextBox Name="text2" HorizontalAlignment="Left" Margin="369,185,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120" RenderTransformOrigin="0.483,4.29"/>
<TextBox Name="text3" HorizontalAlignment="Left" Margin="369,254,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120" RenderTransformOrigin="0.483,4.29"/>
<Button Name="button1" Content="Button" HorizontalAlignment="Left" Margin="572,168,0,0" VerticalAlignment="Top" Width="131" Height="46"/>
</Grid>
</Window>
"#
#Read XAML
$reader=(New-Object System.Xml.XmlNodeReader $xaml)
try{$Form=[Windows.Markup.XamlReader]::Load( $reader )}
catch{Write-Host "Unable to load Windows.Markup.XamlReader"; exit}
# Store Form Objects In PowerShell
$xaml.SelectNodes("//*[#Name]") | ForEach-Object {Set-Variable -Name ($_.Name) -Value $Form.FindName($_.Name)}
#Show Form
$Form.ShowDialog() | out-null

How can i display ComboboxSelectedItem in Textbox

I create a GUI with Visual Studio and import the XAML code in Powershell and i have a problem to display in textbox a value from one of 5 combobox selected item.
I learn by myself and i really love it but i dont have the good method for debbug my code alone,
anybody can have a time and a knowledge for help me please ?
I want to display in textbox ($TxtBox) the selected item (or value) from CboPL or CboTG or CboSB....
with powershell.
This is my XAML code beetwen here string in powershell :
<Window x:Name="Main" x:Class="Printers_Ordi.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Printers_Ordi"
mc:Ignorable="d"
Title="Printers-Ordi" Height="450" Width="728.471">
<Grid x:Name="Wall">
<Grid.Background>
<ImageBrush ImageSource="C:/Users/admsb160365/Desktop/scripts Shell/Imprimantes GHT/Wall.png"/>
</Grid.Background>
<Label x:Name="LabelTitre" Content="Printers-Ordi" HorizontalAlignment="Left" Margin="74,25,0,0" VerticalAlignment="Top" FontFamily="Yu Gothic UI Semibold" FontSize="24" RenderTransformOrigin="0.503,0.76" Height="42" Width="164" Foreground="#FF1346CD"/>
<ComboBox x:Name="CboComputer" HorizontalAlignment="Left" Margin="74,82,0,0" VerticalAlignment="Top" Width="164" FontSize="16" Height="31" IsEditable="True" IsReadOnly="True" Text="Ordinateur"/>
<ComboBox x:Name="CboSites" HorizontalAlignment="Left" Margin="74,118,0,0" VerticalAlignment="Top" Width="164" Height="31" FontSize="16" IsEditable="True" IsReadOnly="True" Text="Sites">
<ComboBox x:Name="CboPL" HorizontalAlignment="Left" VerticalAlignment="Top" Width="154" FontSize="16" IsEditable="True" IsReadOnly="True" Text="Paimpol"/>
<ComboBox x:Name="CboGP" HorizontalAlignment="Left" VerticalAlignment="Top" Width="154" FontSize="16" IsEditable="True" IsReadOnly="True" Text="Guingamp"/>
<ComboBox x:Name="CboSB" HorizontalAlignment="Left" VerticalAlignment="Top" Width="154" FontSize="16" IsEditable="True" IsReadOnly="True" Text="SaintBrieuc"/>
<ComboBox x:Name="CboLN" HorizontalAlignment="Left" VerticalAlignment="Top" Width="154" FontSize="16" IsEditable="True" IsReadOnly="True" Text="Lannion"/>
<ComboBox x:Name="CboTG" HorizontalAlignment="Left" VerticalAlignment="Top" Width="154" FontSize="16" IsEditable="True" IsReadOnly="True" Text="Treguier"/>
</ComboBox>
Thanks by advance for your patience and support ;-)
Continuing from my comments. There are a few ways to deal with your use case. Here is a simple example using Winform. Ultimately, it's still collecting/assigning text from one element(s)/or code results to another.
Add-Type -AssemblyName System.Drawing
$ComboBox = New-Object System.Windows.Forms.ComboBox
$ComboBox.Location = New-Object System.Drawing.Point(10,10)
$ComboBox.Items.AddRange(#('One','Two'))
$RichTextBox = New-Object System.Windows.Forms.RichTextBox
$RichTextBox.Location = New-Object System.Drawing.Point(10,40)
$Form = New-Object System.Windows.Forms.Form
$Form.Controls.Add($ComboBox)
$Form.Controls.Add($RichTextBox)
$ComboBox.Add_TextChanged({
switch($ComboBox.Text){
'One' {$RichTextBox.Text = 'This is one'}
'Two' {$RichTextBox.Text = 'This is two'}
}
})
$Form.ShowDialog()
An example using WPF
[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
[xml]$XAML = #'
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="PowerShell Form" Height="310" Width="350" ResizeMode="NoResize">
<Grid Margin="0,0,0,0">
<GroupBox Header="General" HorizontalAlignment="Left" Height="225" Margin="10,10,0,0" VerticalAlignment="Top" Width="320">
<Grid HorizontalAlignment="Left" Height="206" Margin="0,0,0,0" VerticalAlignment="Top" Width="320">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="60*"/>
<ColumnDefinition Width="250*"/>
</Grid.ColumnDefinitions>
<Label Content="Field #1:" HorizontalAlignment="Left" Margin="0,7,0,0" VerticalAlignment="Top" Height="26" Width="93"/>
<Label Content="Field #2:" HorizontalAlignment="Left" Margin="0,35,0,0" VerticalAlignment="Top" Height="26" Width="93"/>
<Label Content="Field #3:" HorizontalAlignment="Left" Margin="0,65,0,0" VerticalAlignment="Top" Height="26" Width="93"/>
<TextBox Name="f1" HorizontalAlignment="Left" Height="23" Margin="10,10,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="229" Grid.Column="1"/>
<ComboBox Name="f2" HorizontalAlignment="Left" Height="23" Margin="10,38,0,0" VerticalAlignment="Top" Width="229" Grid.Column="1">
<ListBoxItem>Test 1</ListBoxItem>
<ListBoxItem>Test 2</ListBoxItem>
<ListBoxItem>Test 3</ListBoxItem>
</ComboBox>
<TextBox Name="f3" HorizontalAlignment="Left" Height="23" Margin="10,66,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="229" Grid.Column="1"/>
</Grid>
</GroupBox>
<Button Name="Clear" Content="Clear Form" HorizontalAlignment="Left" Margin="10,240,0,0" VerticalAlignment="Top" Width="90" Height="30" RenderTransformOrigin="0.522,0.733"/>
<Button Name="Submit" Content="Submit" Margin="234,240,12,0" VerticalAlignment="Top" Height="30"/>
</Grid>
</Window>
'#
$reader = (New-Object System.Xml.XmlNodeReader $xaml)
try{$Form = [Windows.Markup.XamlReader]::Load( $reader )}
catch
{
Write-Host 'Unable to load Windows.Markup.XamlReader.'
break
}
$xaml.SelectNodes('//*[#Name]') |
ForEach-Object {Set-Variable -Name ($_.Name) -Value $Form.FindName($_.Name)}
$Form.Add_Loaded({
if (Test-Path -Path '.\ComboBox.selection')
{
$cbSelection = Get-Content '.\ComboBox.selection'
[int]$cbSelectionInt = -1
[void][int]::TryParse($cbSelection,[ref]$cbSelectionInt)
if ($cbSelectionInt -ge 0)
{$f2.SelectedIndex = $cbSelectionInt}
}
})
$Clear.Add_Click({
$fields = #('f1','f2','f3')
foreach ($field in $fields)
{
$control = $Form.FindName($field)
switch ($control.GetType()) {
'System.Windows.Controls.TextBox' {$control.Clear()}
'System.Windows.Controls.ComboBox' {$control.SelectedIndex = -1}
DEFAULT {'unknown control'}
}
}
})
$f2.add_SelectionChanged({
param($sender,$args)
$f3.Text = ($($sender.SelectedValue) -replace '.*:\s+')
})
$Form.ShowDialog()

How to add a <remove /> block using Remove-WebConfigurationProperty to a web.config?

I'm trying to add a <remove /> key to a web.config to remove the WebDAV module. Currently the configuration for the web.config is ...
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\Server.Host.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</location>
</configuration>
... and I would like to update it programmatically using PowerShell to the following ...
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<modules>
<remove name="WebDAVModule" />
</modules>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\Server.Host.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</location>
</configuration>
I have tried to use the PowerShell IIS module Remove-WebConfigurationProperty, but I can't get it to add the block.
Remove-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST/Default Web Site/webapp' -Filter "system.webServer/modules" -Name "WebDAVModule" -Location "."
Any help is appreciated.
Thanks #Theo, that was a good suggestion. I used the following PowerShell script to update the web.config.
$PathWebConfig = "C:\web.config";
[xml]$xmlDoc = Get-Content($PathWebConfig);
$Node = $xmlDoc.configuration.location.'system.webServer'.modules;
if ($Node -eq $null) {
Write-Host "Node doesn't exist.";
$xmlNodeModules = $xmlDoc.CreateNode("element","modules","");
$xmlKeyRemove = $xmlDoc.CreateNode("element","remove","");
$xmlKeyRemove.SetAttribute("name","WebDAVModule");
$xmlNodeModules.AppendChild($xmlKeyRemove) | Out-Null;
$xmlDoc.configuration.location.'system.webServer'.AppendChild($xmlNodeModules) | Out-Null;
$xmlDoc.save($PathWebConfig);
} else {
Write-Host "Node exists.";
}

PowerShell XAML ListBox Add_DoubleClick

Quick one. I want to add Add_DoubleClick() to ListBox in PowerShell, but this doesn't work with implemented ListBox via XAML file... and I'm stuck
I will be very grateful for any help here...
I still have msg warning, that my post is mostly code, so I need to write something here...
# $ErrorActionPreference= 'silentlycontinue'
Add-Type -AssemblyName PresentationFramework, PresentationCore, WindowsBase, System.Windows.Forms, System.Drawing
$ScriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path
$AssemblyLocation = Join-Path -Path $ScriptPath -ChildPath .\themes
foreach ($Assembly in (Dir $AssemblyLocation -Filter *.dll)) {
[System.Reflection.Assembly]::LoadFrom($Assembly.fullName) | out-null
}
[xml]$xaml = #"
<Controls:MetroWindow
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
Title="ddd"
Height="500"
Width="800"
BorderThickness="0"
GlowBrush="{DynamicResource AccentColorBrush}"
ResizeMode="CanResizeWithGrip"
WindowStartupLocation="CenterScreen">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Cyan.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.AnimatedTabControl.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
</ResourceDictionary.MergedDictionaries>
</Window.Resources>
<Grid>
<ListBox SelectionMode="Single" ItemsSource="{Binding}" x:Name="ListBox" HorizontalAlignment="Right" Height="100" Margin="244,144,0,0" VerticalAlignment="Top" Width="112">
<ListBoxItem Content="Coffie"></ListBoxItem>
</ListBox>
</Grid>
</Controls:MetroWindow>
"#
#Read the form
$Reader = (New-Object System.Xml.XmlNodeReader $xaml)
$Form = [Windows.Markup.XamlReader]::Load($reader)
#AutoFind all controls
$xaml.SelectNodes("//*[#*[contains(translate(name(.),'n','N'),'Name')]]") | ForEach-Object {
New-Variable -Name $_.Name -Value $Form.FindName($_.Name) -Force
}
$ListBox.Items.AddRange()
$ListBox.Add_DoubleClick({
$TextBox2.AppendText("dddd`r`n")
})
...`
I used different approach to my problem:
$smth.Add_IsMouseCapturedChanged({
$smth.SelectedIndex = -1
})