Found it!
Create your form and use my code from here to give that form your own icon.
Then, from a button for example on the form, you open the OpenFile dialog, using your function. The dialog will then have the icon used in your form.
# start the code with your own function to show the OpenFile dialog
function Invoke-OpenFileDialog {
Param (
[Parameter(Mandatory=$true, Position=0)] [string] $Title,
[Parameter(Mandatory=$true, Position=1)] [string] $InitialDirectory,
[Parameter(Mandatory=$true, Position=2)] [string] $Filter
)
if ($InitialDirectory -ne "") {
if (!(Test-Path -LiteralPath $InitialDirectory -PathType Container)) {
$InitialDirectory = ([System.IO.FileInfo]$InitialDirectory).DirectoryName
}
}
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.Filter = $Filter
$OpenFileDialog.InitialDirectory = $InitialDirectory
$OpenFileDialog.Title = $Title
$result = $OpenFileDialog.ShowDialog()
$OpenFileDialog.Dispose()
if ($result -eq 'OK') {
return $OpenFileDialog.FileName
}
else { return "" }
}
# next, create your form (just a simple demo below) and from there show the dialog
# (I'm using a button on the form to do this)
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()
$form = New-Object system.Windows.Forms.Form
$form.ClientSize = '400,230'
$form.text = "Test"
$form.TopMost = $false
# This base64 string holds the bytes that make up the 16x16 StackOverflow icon
$iconBase64 = @'
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAAsTAAALEwEAmpwYAAAB
tUlEQVQ4y5WSTUtUYRzFf/d6r00FMQPCFG3yUsyYH6BCooUv5ZeoIImEghauMojqAwQu3QSSZEEt
KmozgwVGYC+EFGTGtcHc1DgSjI339bQwJsaZUeesHv7PeQ7nf85jSBLbQJXfgDB2J+vuTHYA78Ew
/pNRiILWBPRnFYD206OEC9MEsxMNSM0QVLR256S857ekOJL/5q7Kt7OKlj7U0Jo7sBK0D1wj/PSU
9alhrO5BrOwA3uMRVC5uvUL84yPxyiLW0TMkzt0j/jnP+sRZ7BMXkGL8Z9erXKNRC96jq4SfX2Bl
+7F7LmIkD+I9vEz86xt2zxBmx2HaMr3NBUBEX6cJZsaJlt7TdugY9vHzhF9yWNn+6uOGIUbLc4qW
56SgIkkKC29VmRxS+eYR+a/H67Kuc+BNXSKcz4NpYXZ0Yqa7MPd3gWFidQ9i7DtQ49WQpEXXxXVd
evv60FqRuOiiUoG4VEAr34lXC6hUYM/ILPlXMziOQ6fjbJS1efvw3f3/6tYujHQGM53ZGNiJ+rY3
D/yXY02/hn3qyvYCe28s0ApqBPK5HK3CAkimUjj/QtkJkqlU9fwXBBkCP6jNZvAAAAAASUVORK5C
YII=
'@
$iconBytes = [Convert]::FromBase64String($iconBase64)
$stream = New-Object IO.MemoryStream($iconBytes, 0, $iconBytes.Length)
$stream.Write($iconBytes, 0, $iconBytes.Length)
$form.Icon = [System.Drawing.Icon]::FromHandle((New-Object System.Drawing.Bitmap -Argument $stream).GetHIcon())
$button = New-Object System.Windows.Forms.Button
$button.Size = New-Object System.Drawing.Size(90,24)
$button.Left = $form.Width - $button.Width - 40
$button.Top = $form.Height - $button.Height * 3
$button.Text = 'Open File'
$button.Add_Click({
# in here, we use your function
$title = 'OpenFileDialog Title'
$initialDirectory = ([System.IO.FileInfo]"C:\Users\").DirectoryName
$filter = 'All files (*.*)| *.*'
$filePicked = Invoke-OpenFileDialog -Title $title -InitialDirectory $initialDirectory -Filter $filter
# Then use this to check if the picker has done its job.
if ($filePicked -ne "") {
$filePicked
Write-Host 'File Picked...'
}
else {
Write-Host 'File Not Picked...'
}
})
$form.Controls.Add($button)
[void]$form.ShowDialog()
# when done, dispose of the form
$form.Dispose()
Now, if you run this, you'll see the form:

and if you click the button, the dialog shows up, including your forms icon:

You can do this for a WPF UI aswell, although setting a WPF form with an embedded icon is slightly different:
# start the code with your own function to show the OpenFile dialog
function Invoke-OpenFileDialog {
Param (
[Parameter(Mandatory=$true, Position=0)] [string] $Title,
[Parameter(Mandatory=$true, Position=1)] [string] $InitialDirectory,
[Parameter(Mandatory=$true, Position=2)] [string] $Filter
)
if ($InitialDirectory -ne "") {
if (!(Test-Path -LiteralPath $InitialDirectory -PathType Container)) {
$InitialDirectory = ([System.IO.FileInfo]$InitialDirectory).DirectoryName
}
}
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.Filter = $Filter
$OpenFileDialog.InitialDirectory = $InitialDirectory
$OpenFileDialog.Title = $Title
$result = $OpenFileDialog.ShowDialog()
$OpenFileDialog.Dispose()
if ($result -eq 'OK') {
return $OpenFileDialog.FileName
}
else { return "" }
}
Add-Type -AssemblyName PresentationFramework
Add-Type -AssemblyName System.Windows.Forms
[xml]$xaml = @"
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Name="Window" Title="Initial Window" WindowStartupLocation = "CenterScreen"
Width = "400" Height = "230" ShowInTaskbar = "True">
<Button x:Name = "Button" Height = "24" Width = "90" Content = 'Open File' />
</Window>
"@
$reader=(New-Object System.Xml.XmlNodeReader $xaml)
$Window=[Windows.Markup.XamlReader]::Load( $reader )
# This base64 string holds the bytes that make up the 16x16 StackOverflow icon
$iconBase64 = @'
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAAsTAAALEwEAmpwYAAAB
tUlEQVQ4y5WSTUtUYRzFf/d6r00FMQPCFG3yUsyYH6BCooUv5ZeoIImEghauMojqAwQu3QSSZEEt
KmozgwVGYC+EFGTGtcHc1DgSjI339bQwJsaZUeesHv7PeQ7nf85jSBLbQJXfgDB2J+vuTHYA78Ew
/pNRiILWBPRnFYD206OEC9MEsxMNSM0QVLR256S857ekOJL/5q7Kt7OKlj7U0Jo7sBK0D1wj/PSU
9alhrO5BrOwA3uMRVC5uvUL84yPxyiLW0TMkzt0j/jnP+sRZ7BMXkGL8Z9erXKNRC96jq4SfX2Bl
+7F7LmIkD+I9vEz86xt2zxBmx2HaMr3NBUBEX6cJZsaJlt7TdugY9vHzhF9yWNn+6uOGIUbLc4qW
56SgIkkKC29VmRxS+eYR+a/H67Kuc+BNXSKcz4NpYXZ0Yqa7MPd3gWFidQ9i7DtQ49WQpEXXxXVd
evv60FqRuOiiUoG4VEAr34lXC6hUYM/ILPlXMziOQ6fjbJS1efvw3f3/6tYujHQGM53ZGNiJ+rY3
D/yXY02/hn3qyvYCe28s0ApqBPK5HK3CAkimUjj/QtkJkqlU9fwXBBkCP6jNZvAAAAAASUVORK5C
YII=
'@
$iconBytes = [Convert]::FromBase64String($iconBase64)
$stream = New-Object IO.MemoryStream($iconBytes, 0, $iconBytes.Length)
$stream.Write($iconBytes, 0, $iconBytes.Length)
# set the form's icon
$Window.Icon = [System.Windows.Media.Imaging.BitmapFrame]::Create($stream)
# connect to the button
$button = $Window.FindName("Button")
$button.Add_Click({
# in here, we use your function
$title = 'OpenFileDialog Title'
$initialDirectory = ([System.IO.FileInfo]"C:\Users\").DirectoryName
$filter = 'All files (*.*)| *.*'
$filePicked = Invoke-OpenFileDialog -Title $title -InitialDirectory $initialDirectory -Filter $filter
# Then use this to check if the picker has done its job.
if ($filePicked -ne "") {
$filePicked
Write-Host 'File Picked...'
}
else {
Write-Host 'File Not Picked...'
}
})
$null = $Window.ShowDialog()