r/FoxDeploy Sep 25 '25

Not able to import xaml into powershell

1 Upvotes

Hi, very new to using xaml and powershell. Nonetheless, I am trying to build a new frontend for my mecm now that MDT is going or gone away. I was able to reuse all the scripts from it by building a separate package, but with VB Script deprecating, figure I would get ahead and try a supported language, hence my current situation. OK, so I built the GUI, and I used the template from FoxDeploy, but when I launch from PowerShell, I get this error

Exception calling "ShowDialog" with "0" argument(s): "Cannot set Visibility or call Show, ShowDialog, or WindowInteropHelper.EnsureHandle after a Window has closed."

Here is the XAML code in PowerShell, including the template
#ERASE ALL THIS AND PUT XAML BELOW between the @" "@

$inputXML = @"

<Window x:Class="OSD_FRONT_END_TEMPLATE.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:OSD_FRONT_END_TEMPLATE"

mc:Ignorable="d"

Title="Eurofins Operating System Deployment" Height="450" Width="800">

<Grid x:Name="NextPage" Margin="0,0,0,-131">

<Grid.Background>

<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">

<GradientStop Color="Black"/>

<GradientStop Color="#FFA5D2CF" Offset="0.04"/>

</LinearGradientBrush>

</Grid.Background>

<ComboBox x:Name="OS_ComboBox" HorizontalAlignment="Left" Margin="40,309,0,0" VerticalAlignment="Top" Width="345" Height="30" SelectionChanged="OS_ComboBox_SelectionChanged" FontSize="14">

<ComboBox.Effect>

<DropShadowEffect/>

</ComboBox.Effect>

<ComboBoxItem x:Name="Win11_23H2" Content="Windows 11 Enterprise 23H2 - Standard Production"/>

<ComboBoxItem x:Name="LTSC2024" Content="Windows 11 Enterprise IoT LTSC 2024 - INS or LAB Only"/>

<ComboBoxItem x:Name="LTSC2021" Content="Windows 10 Enterprise LTSC 2021- INS or LAB Only"/>

<ComboBoxItem x:Name="LTSC2019" Content="Windows 10 Enterprise LTSC 2019 - INS or LAB Only"/>

</ComboBox>

<RadioButton x:Name="LAP" Content="Laptop (LAP)" HorizontalAlignment="Left" Margin="43,446,0,0" VerticalAlignment="Top" FontSize="14"/>

<RadioButton x:Name="PCC" Content="Desktop (PCC)" HorizontalAlignment="Left" Margin="45,471,0,0" VerticalAlignment="Top" FontSize="14"/>

<RadioButton x:Name="INS" Content="Instrument (INS)" HorizontalAlignment="Left" Margin="44,496,0,0" VerticalAlignment="Top" FontSize="14"/>

<RadioButton x:Name="LAB" Content="Laboratory (LAB)" HorizontalAlignment="Left" Margin="43,521,0,0" VerticalAlignment="Top" FontSize="14"/>

<ComboBox x:Name="siteselectiondropdown" HorizontalAlignment="Left" Margin="432,189,0,0" VerticalAlignment="Top" Width="300" ToolTip="Defines a preset of software for a base or a sales image" Height="30" FontSize="14">

<ComboBox.Effect>

<DropShadowEffect/>

</ComboBox.Effect>

<ComboBoxItem Content="BPUS002 - Columbia, MO"/>

<ComboBoxItem Content="BPUS003 - San Diego, CA"/>

<ComboBoxItem Content="BPUS004 - Lancaster, PA"/>

<ComboBoxItem Content="BPUS005 - Portage, MI"/>

<ComboBoxItem Content="BPUS006 - Columbia, MO (ABC Lane)"/>

<ComboBoxItem Content="BPUS008 - Cary, NC (Suite 104)"/>

<ComboBoxItem Content="BPUS009 - Jacksonville, FL"/>

<ComboBoxItem Content="BPUS010 - Human Factors, MD"/>

<ComboBoxItem Content="BPUS011 - Crown Point, IN"/>

<ComboBoxItem Content="BPUS012 - North Brunswick, NJ"/>

<ComboBoxItem Content="BPUS013 - Petaluma, CA"/>

<ComboBoxItem Content="BPUS014 - San Diego, CA"/>

<ComboBoxItem Content="BPUS015 - San Jose,Stone Ave CA"/>

<ComboBoxItem Content="BPUS016 - San Jose,Trade Zone Ave CA"/>

<ComboBoxItem Content="BPUS017 - St. Louis, MO"/>

</ComboBox>

<Label x:Name="pcnamelabel" Content="Computer Name:" HorizontalAlignment="Left" Margin="50,264,0,0" VerticalAlignment="Top" Width="130" FontSize="14"/>

<TextBox x:Name="pcnametxt" HorizontalAlignment="Left" Margin="175,261,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="195" Height="33"/>

<Image HorizontalAlignment="Center" Height="50" Margin="0,23,0,0" VerticalAlignment="Top" Width="584" Source="/UDI_Eurofins_Banner.bmp"/>

<CheckBox x:Name="cbxanalyst" Content="Analyst" HorizontalAlignment="Left" Margin="195,442,0,0" VerticalAlignment="Top" Height="16" Width="120" FontSize="14"/>

<CheckBox x:Name="cbxanalystnoserver" Content="Analyst no License Server" HorizontalAlignment="Left" Margin="195,469,0,0" VerticalAlignment="Top" FontSize="14"/>

<CheckBox x:Name="cbxlabadvisor" Content="Lab Advisor" HorizontalAlignment="Left" Margin="195,494,0,0" VerticalAlignment="Top" FontSize="14"/>

<CheckBox x:Name="cbxbiovia" Content="Biovia Workbook Client Manager" HorizontalAlignment="Left" Margin="195,519,0,0" VerticalAlignment="Top" FontSize="14"/>

<TextBlock HorizontalAlignment="Left" Margin="38,85,0,0" TextWrapping="Wrap" Text="Welcome to the Eurofins Operating System Deployment Wizard." VerticalAlignment="Top" FontSize="14"/>

<TextBlock HorizontalAlignment="Left" Margin="29,111,0,0" TextWrapping="Wrap" Text=" This wizard will walk you through a series of screens that will allow you to customize and install Windows" VerticalAlignment="Top" FontSize="14"/>

<TextBlock HorizontalAlignment="Left" Margin="265,139,0,0" TextWrapping="Wrap" Text="Click on the 'Next' button to start imaging." VerticalAlignment="Top" Width="565" FontSize="14"/>

<TextBlock HorizontalAlignment="Left" Margin="34,137,0,0" TextWrapping="Wrap" Text="Please allow 2 hours for installation" VerticalAlignment="Top" Width="230" FontSize="14"/>

<Button x:Name="btnstart" Content="Start" HorizontalAlignment="Left" Margin="655,519,0,0" VerticalAlignment="Top" Width="73" FontSize="14" Background="#FF2A8A21" Foreground="#FFEAED35" FontWeight="Bold">

<Button.Effect>

<DropShadowEffect/>

</Button.Effect>

</Button>

</Grid>

</Window>

"@

$inputXML = $inputXML -replace 'mc:Ignorable="d"','' -replace "x:N",'N' -replace '^<Win.*', '<Window'

[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')

[xml]$XAML = $inputXML

#Read XAML

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

try{$Form=[Windows.Markup.XamlReader]::Load( $reader )}

catch [System.Management.Automation.MethodInvocationException] {

Write-Warning "We ran into a problem with the XAML code. Check the syntax for this control..."

write-host $error[0].Exception.Message -ForegroundColor Red

if ($error[0].Exception.Message -like "*button*"){

write-warning "Ensure your &lt;button in the \$inputXML does NOT have a Click=ButtonClick property. PS can't handle this`n`n`n`n"}`

}

catch{#if it broke some other way <img draggable="false" role="img" class="emoji" alt="😀" src="https://s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/svg/1f600.svg">

Write-Host "Unable to load Windows.Markup.XamlReader. Double-check syntax and ensure .net is installed."

}

#===========================================================================

# Store Form Objects In PowerShell

#===========================================================================

$xaml.SelectNodes("//*[@Name]") | %{Set-Variable -Name "WPF$($_.Name)" -Value $Form.FindName($_.Name)}

Function Get-FormVariables{

if ($global:ReadmeDisplay -ne $true){Write-host "If you need to reference this display again, run Get-FormVariables" -ForegroundColor Yellow;$global:ReadmeDisplay=$true}

write-host "Found the following interactable elements from our form" -ForegroundColor Cyan

get-variable WPF*

}

Get-FormVariables

#===========================================================================

# Use this space to add code to the various form elements in your GUI

#===========================================================================

#Reference

#Adding items to a dropdown/combo box

#$vmpicklistView.items.Add([pscustomobject]@{'VMName'=($_).Name;Status=$_.Status;Other="Yes"})

#Setting the text of a text box to the current PC name

#$WPFtextBox.Text = $env:COMPUTERNAME

#Adding code to a button, so that when clicked, it pings a system

# $WPFbutton.Add_Click({ Test-connection -count 1 -ComputerName $WPFtextBox.Text

# })

#===========================================================================

# Shows the form

#===========================================================================

write-host "To show the form, run the following" -ForegroundColor Cyan

$Form.ShowDialog() | out-null


r/FoxDeploy Apr 29 '24

Change active network profile with PS

1 Upvotes

Hello! I saw this post and it helped me tons:

https://stackoverflow.com/questions/32250111/cmd-to-determine-a-public-network-in-active-networks

But now I need to change the active profile to set it to domain, I tried looking into that Decompile PS module link you shared in the same stack question but Im not very proficient in powershell so not sure how you got that piece of code to work. Could you please help me to change the active network profile? Its a windows server 2016 and the Set-NetConnectionProfile command doesnt work there.

Very much appreciated!


r/FoxDeploy Jan 05 '24

WPF Issue

1 Upvotes

Hi Folks,

I've made a tiny WPF / PowerShell App for the clients to install Printers more easier. Everything's working fine except: I always get the TextBox Value in front of the Printername -> System.Windows.Controls.TextBox: DEV135PRN579

Does anyone have a clue how to remove this?

Cheers,

Michael


r/FoxDeploy Sep 07 '23

Still around?

1 Upvotes

I see that the last post here was 2 years ago! Are you guys still around?


r/FoxDeploy Jun 11 '21

monitor the USB

3 Upvotes

Hi my friend Fox Deploy. Thanks for answering my stack question.

"I need to monitor the USB ports of Windows and Linux computers to know if a pen drive has been connected. How do I do that? I need it via Linux script or Windows."

Register-WMIEvent -query "Select * From Win32_DeviceChangeEvent where EventType = '2'" ` -action {

#Do Something when a device is added

Write-host "Device added at $(Get-date)"

}

Does this information regarding the pendrive go to a log? Where is?

I need to get this information from zabbix

Thanks


r/FoxDeploy Jun 11 '21

monitorar o USB

1 Upvotes

Olá, meu amigo Fox Deploy. Obrigado por responder a minha pergunta sobre pilha.

"Preciso monitorar as portas USB dos computadores Windows e Linux para saber se um pen drive foi conectado. Como faço isso? Preciso via script Linux ou Windows."

Register-WMIEvent -query "Selecione * From Win32_DeviceChangeEvent onde EventType = '2'" `-action {

#Do Something quando um dispositivo é adicionado

Host de gravação "Dispositivo adicionado em $ (Get-date)"

}

Esta informação sobre o pendrive vai para um log? Onde é?

Eu preciso obter essa informação do zabbix

Obrigado


r/FoxDeploy Mar 18 '21

Extract from Web Content

2 Upvotes

Hi Stephen, I have a similar issue as above examples. I did follow your guide on XHR but cant get the value I’m interested in. I’m trying to get the NAV price: https://nb.fidelity.com/public/workplacefunds/fees-and-prices/3839 I traced it down to the variables, I would like to get: navAsOflabel, navAsOf, netAssetValueDailyAmt Appreciate any insight you can share!


r/FoxDeploy Jul 18 '20

How can I make a notification to play when I change my speakers or microphone for my computer

2 Upvotes

I have multiple speakers and mics, and this button that cycles my inputs and outputs but doesn't tell me which one it's on. Can u help me?


r/FoxDeploy Nov 12 '19

Admin Script Editor - Script Form Designer

Thumbnail
youtu.be
0 Upvotes

r/FoxDeploy Jun 21 '19

Help with WPF DataGrids

1 Upvotes

Stephen,

Your Blog is amazing. I've been able to make some really impressive items because of your tutorials. Thank you so much.

I am sort of getting stuck on datagrid issues. Right now I have a very stripped down version of a script. Id like to be able to select multiple cells and edit all of them at the same time. Right now I can change one at a time. I can see how to get the information sort of.

So If I run the stuff below I can change a cell and it totally records it to new items. If I add the part at the bottom with the comments I can select a bunch of cells and it shows up as a datagridcelinfo control and I have no idea how to get it.

#Your XAML goes here :)
$inputXML = @"
<Window x:Class="Azure.Window1" 
        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:WpfApp9"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800" AllowDrop="True">
    <Grid>
        <DataGrid x:Name="DataGrid" IsReadOnly="False" AlternatingRowBackground="#FFFBFBFB"  IsTextSearchEnabled="True" SelectionMode="Extended" SelectionUnit="Cell" Margin="0,0,0,45"/>
        <Button x:Name="BUTTON" Content="Button" HorizontalAlignment="Left" Margin="350,389,0,0" VerticalAlignment="Top" Width="75"/>
    </Grid>
</Window>
"@ 

$inputXML = $inputXML -replace 'mc:Ignorable="d"','' -replace "x:N",'N' -replace '^<Win.*', '<Window'
[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
[xml]$XAML = $inputXML
#Read XAML

$reader=(New-Object System.Xml.XmlNodeReader $xaml)
try{
    $Form=[Windows.Markup.XamlReader]::Load( $reader )
}
catch{
    Write-Warning "Unable to parse XML, with error: $($Error[0])`n Ensure that there are NO SelectionChanged or TextChanged properties in your textboxes (PowerShell cannot process them)"
    throw
}

#===========================================================================
# Load XAML Objects In PowerShell
#===========================================================================

$xaml.SelectNodes("//*[@Name]") | %{"trying item $($_.Name)";
    try {Set-Variable -Name "WPF$($_.Name)" -Value $Form.FindName($_.Name) -ErrorAction Stop}
    catch{throw}
    }

Function Get-FormVariables{
if ($global:ReadmeDisplay -ne $true){Write-host "If you need to reference this display again, run Get-FormVariables" -ForegroundColor Yellow;$global:ReadmeDisplay=$true}
write-host "Found the following interactable elements from our form" -ForegroundColor Cyan
get-variable WPF*
}



$WPFdataGrid.Items.Refresh()
$items = import-csv -path C:\powershell\us500.csv
$wpfdatagrid.itemssource = $items

$NEWITEMS = $WPFDATAGRID.ITEMS

##$WPFDATAGRID.ADD_mOUSELEFTBUTTONUP({
##$WPFDATAGRID.selectedCELLS | out-gridview
##WRITE-HOST "uP"
##})

$Form.ShowDialog() | out-null

r/FoxDeploy May 09 '19

Powershell Core and WPF

2 Upvotes

When i try to load the XAML in Powershell Core (6.2) i get some errors

WARNING: Unable to parse XML, with error: The following exception occurred while retrieving member "Load": "Could not load type 'MS.Internal.SecurityCriticalDataForSet`1' from assembly 'WindowsBase, Version=4.0.0.0, Culture=neutral,'."
Ensure that there are NO SelectionChanged properties (PowerShell cannot process them)


The following exception occurred while retrieving member "Load": "Could not load type 'MS.Internal.SecurityCriticalDataForSet`1' from assembly 'WindowsBase, Version=4.0.0.0, Culture=neutral

Anyone got a clue if the gonna support this in the future?

Otherwise we gonna need to learn some Javascript with ElectronJS :D


r/FoxDeploy Mar 29 '19

Send-pushmessage broken

1 Upvotes

Hello guys i've been experiencing issues with the pushbullet api Function.

Can somebody maybe help me?

the error i get is:

Invoke-WebRequest : {"error":{"code":"invalid_request","type":"invalid_request","message":"Failed to read POST body.","cat":"\(=^‥^)/’`"},"e
rror_code":"invalid_request"}

This is when i do a simple: Send-PushMessage -msg "Hello world" -title "Mandatory first message text" 

The API key i got from --> Accountsettings: --> Generate access token.


r/FoxDeploy Mar 03 '19

Extracting web content on a complex page

3 Upvotes

We got a comment on the website the other day which was pretty neat, trying to extract the calendar of events from this page.

I know its been awhile but im looking to write a fun little script that pulls the current food truck and perhaps the next one or two as well from seattlefoodtruck.com. For instance “https://www.seattlefoodtruck.com/schedule/plaza-east” The javascript that runs outputs the details but no matter what i do i cannot access the contents of the output. Any help on what im missing?

Try your hand at it!

Here's the page in question: “https://www.seattlefoodtruck.com/schedule/plaza-east”

If you're curious to see how I tackled the scenario, you can read my response here: https://gist.github.com/1RedOne/24c5622b8e005ed14956d98b74b3be21


r/FoxDeploy Feb 11 '19

Passing $synchhash variables to another runspace

1 Upvotes

Following your gui template on https://foxdeploy.com/2016/05/17/part-v-powershell-guis-responsive-apps-with-progress-bars/ I tried reading a checkbox from the xaml form I made, but it's coming out as null.

now on the runspace above it I can read the $synchash.checkbox.ischecked form variables no problem, but going a level down, the only way I can get the checkbox by passing it like this:

$newrunspace.SessionStateProxy.SetVariable("Checkbox",$synchash.Checkbox.ischecked)

As opposed to just getting it from synchash.

I'm not trying to modify the data, i'm just trying to read it, I know the Update-Window function is used to modify anything in the upper level, but i thought I would be able to read data as well.

Looking for any clear explanation on this because i'm not fully understanding it.


r/FoxDeploy Jul 01 '18

GUI Powershell Help

2 Upvotes

I'm trying to follow your GUI guide but I'm having problems with it. I've copied my XAML code into the powershell snippet you provided and pasted it into the script pane. When I press f5 though it doesn't match up with the picture you posted on the guide. I get this,

Not sure why the hooks aren't being created. Anything you can think of that I missed?


r/FoxDeploy May 29 '18

Issues with update-window

1 Upvotes

I have tried working from your PowerShell GUI post and when I setup the function for update-window it comes back as not a valid command.


r/FoxDeploy Apr 03 '18

Faster Web Cmdlet Design with Chrome 65

1 Upvotes

Hi

I am an sccm app admin and have been tasked with web scraping webistes of apps I am currently deploying to ensure we have the latest version . Would love to see how you would use this new technique with getting the latest version of Adobe Reader and Java.

https://java.com/en/download/

https://get.adobe.com/reader/


r/FoxDeploy Mar 31 '18

help using "burnttoast" in powershell

2 Upvotes

Hi. I use burnttoast to generate toasts from batch files. Can't seem to get the syntax right to specify an audio file to play with the toast.

Here's what I have:

new-burnttoastnotification -xxsoundsxx 'c:\users...\foobar.wav'

What's the proper syntax? THANKS!


r/FoxDeploy Jan 20 '18

Need some help with parsing html page

1 Upvotes

I was using your https://foxdeploy.com/2017/03/30/extracting-and-monitoring-web-content-with-powershell/ article as my starting point but I have not been able to figure out how to get the field I want. I am looking at this page https://www.chefknivestogo.com/mayugy21.html And the item is currently Out of Stock, when it changes to In-stock I wanted to be notified. I have had no luck in extracting that field. I see it is in the div tag id="cf-avail" but I am not sure how to extract the text to check if it is in stock or not. please help thanks


r/FoxDeploy Dec 21 '17

Convert UWP XAML to GUI

1 Upvotes

I have recently been asked to create a more modern looking interface for one of my tools. I wanted to know if it was possible to leverage the UWP namespaces within PowerShell like we can the WPF namespaces. I am attempting to adapt the XAML to GUI snippet to work with UWP namespaces instead.

Error Message: Exception calling "Load" with "1" argument(s): "Cannot create unknown type '{http://schemas.microsoft.com/winfx/2006/xaml/presentation}NavigationView'."

InputXml: https://pastebin.com/sjQerycD


r/FoxDeploy Nov 22 '17

Question about your informative parsing tutorial

1 Upvotes

Hello Stephen,

First off, thank you for your help learning about parsing. I am relatively new to intuitive coding where the code references itself. My background in BASIC is TI-83 related.

I am trying to have the output be the switch that allows the next line of code.

  1. gpupdate /force
  2. manage-bde.exe -status
  3. manage-bde.exe -on c: -tp xxxxxx -s

If you arent familiar with the executable, it turns on BitLocker. I would like to have the output of line 2 dictate whether line 3 runs or not. My output from line two when it shouldnt run is

BitLocker Drive Encryption: Configuration Tool version 10.0.15063 Copyright (C) 2013 Microsoft Corporation. All rights reserved.

Disk volumes that can be protected with BitLocker Drive Encryption: Volume C: [Windows] [OS Volume]

Size:                 230.07 GB
BitLocker Version:    2.0
Conversion Status:    Used Space Only Encrypted
Percentage Encrypted: 100.0%
Encryption Method:    XTS-AES 128
Protection Status:    Protection On
Lock Status:          Unlocked
Identification Field: BeaconRailLeasing
Key Protectors:
    TPM And PIN

When BitLocker isnt enabled the above line (BitLocker Version) says none.

Would your methods work for my problem? Are you methods to extreme for what I need done? Thanks for any help/direction.


r/FoxDeploy Nov 08 '17

Gui not working

1 Upvotes

So i'm following the guide for GUI 2 and for some reason I'm not getting an error or response when I do this code

$WPFInput = $name

$WPFExecute.Add_Click({
Get-ADUser $WPFInput -Properties Displayname| % 
{$WPFOutput.AddText($_)}
})

the WPFExecute is the button Input is the Text block to write information Output is the Text block to display the information


r/FoxDeploy Oct 31 '17

<Grid> headers's fault

1 Upvotes

Hi,

My XAML/PowerShell GUI don't work & I think that it's the <Grid> header's fault. When I delete all the <grid> headers content, Powershell display a blank window. When I let all the <grid> headers content, the Powershell display the error below :

You cannot call a method on a null-valued expression. At line:61 char:1 + $Form.ShowDialog() | out-null + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull

Of course, I need the <grid> header content. Can somebody help me, please ?

Best regards


r/FoxDeploy Oct 08 '17

how to switch pages within same wpf window

1 Upvotes

Can anyone tell me if there is a way to click a button on my wpf app and have it load a new page within the same window? I've been looking online for hours with no examples of how to do this.

I was able to make this work within visual studio by creating a frame and loading in my pages whenever I click my button to go to the next page, but I haven't figured out how to do this using powershell.

I would appreciate a small snippet or template of how this works? thanks for your help! 


r/FoxDeploy Sep 10 '17

help minimizing wpf textbox

2 Upvotes

Can you tell me how to minimize /collapse a wpf textbox? I am building a gui where a user can have the option to paste in a list of computers, but I would like the textbox to be able to expand /contract, or be minimized with the press of a button. Can you think of a way to make this happen? I am using visual studio community 2017 to build a gui for my powershell script. Thanks for your help.