I wrote a script to display a message box. It works well in PowerShell 5, but doesn't PowerShell 6. How can I make it work?
Script I wrote(extracted):
function test
{
[CmdletBinding()]
param([Parameter(Mandatory = $true, Position = 0)][string]$directory)
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName Microsoft.Visualbasic
Add-Type -AssemblyName System.Drawing
#----------------------------
}
Error message:
Add-Type : Cannot find path 'C:\Users\Owner\System.Windows.Forms.dll' because it does not exist. At C:\Users\Owner\Desktop\sample\trans-search.ps1:8 char:6 + Add-Type -AssemblyName System.Windows.Forms + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (C:\Users\Owner\System.Windows.Forms.dll:String) [Add-Type], ItemNotFoundException + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.AddTypeCommand
Thank you for your help.
using assembly System.Windows.Forms; using namespace System.Windows.Forms; [messagebox]::show('hello world')
– js2010