I try a simple example from

[xml]$xaml = @"




x:Name="Window" Title="Initial Window" WindowStartupLocation = "CenterScreen"

SizeToContent = "WidthAndHeight" ShowInTaskbar = "True" Background = "lightgray"> 

<StackPanel > 

    <RadioButton x:Name="Item1" Content = 'Item1'/>

    <RadioButton x:Name="Item2" Content = 'Item2'/>

    <RadioButton x:Name="Item3" Content = 'Item3'/>  

    <TextBox />      



$reader=(New-Object System.Xml.XmlNodeReader $xaml)

$Window=[Windows.Markup.XamlReader]::Load( $reader )

$xaml.SelectNodes(“//[@[contains(translate(name(.),‘n’,‘N’),‘Name’)]]”) | ForEach


Set-Variable -Name ($_.Name) -Value $Window.FindName($_.Name)


$Window.Showdialog() | Out-Null

I get error:

[ERROR] Unable to find type [Windows.Markup.XamlReader].

[ERROR] At line:17 char:9

[ERROR] + $Window=[Windows.Markup.XamlReader]::Load( $reader )

[ERROR] + ~~~~~~~~~~~~~~~~~~~~~~~~~~~

[ERROR] + CategoryInfo : InvalidOperation: (Windows.Markup.XamlReader:Typ

[ERROR] eName) , RuntimeException

[ERROR] + FullyQualifiedErrorId : TypeNotFound


cmdlet ForEach-Object at command pipeline position 1

Supply values for the following parameters:

Process: Name Bill

[ERROR] ForEach-Object : Cannot bind parameter ‘Process’. Cannot convert the "Name

[ERROR] Bill" value of type “System.String” to type

[ERROR] “System.Management.Automation.ScriptBlock”.

[ERROR] At line:20 char:77

[ERROR] + … des(“//[@[contains(translate(name(.),‘n’,‘N’),‘Name’)]]”) | ForEach

[ERROR] + ~~~~~~~

[ERROR] + CategoryInfo : InvalidArgument: (:slight_smile: [ForEach-Object], Parameter

[ERROR] BindingException

[ERROR] + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerSh

[ERROR] ell.Commands.ForEachObjectCommand


Set-Variable -Name ($_.Name) -Value $Window.FindName($_.Name)

[ERROR] You cannot call a method on a null-valued expression.

[ERROR] At line:25 char:1

[ERROR] + $Window.Showdialog() | Out-Null

[ERROR] + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

[ERROR] + CategoryInfo : InvalidOperation: (:slight_smile: , RuntimeException

[ERROR] + FullyQualifiedErrorId : InvokeMethodOnNull


Please advise as to what went wrong.

Since the example is older than vs2019, that shouldn’t be the issue.

I have PowerShell extensions installed.

You haven’t really asked a question. What are you trying to accomplish, what is not working?

The first error is a pretty good indicator of what is wrong.

I am a little closer.
I had to add:
Add-Type -Assembly PresentationFramework

but the lines:
$xaml.SelectNodes(“//[@[contains(translate(name(.),‘n’,‘N’),‘Name’)]]”) | ForEach
Set-Variable -Name ($.Name) -Value $Window.FindName($.Name)
generate a dialog box:

that doesn’t seem to do anything.
Is it even supposed to be there?

Welcome to the forum. :wave:t3:

I’d really help us reading your posts when you formatted your code as code here in the forum.

So when you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in 1 <---- Click :point_up_2:t4: :wink:

Just a guess, but the XPath query is likely wrong. I know it can be very temperamental, plus I think you need a namespace. I have little to no experience using XPath so I can not offer more help on that

Not sure if it is code formatting as Olaf suggests … but have you tried using $_.Name instead of $.Name.

Add-Type -Assembly PresentationFramework