I'm trying to get MessageBox dialog called from a class using the following code
Add-Type -Assembly PresentationFramework
[System.Windows.MessageBox]::Show('MessageBox is out of the class')
Class TestClass {
TestClass(){
[System.Windows.MessageBox]::Show('MessageBox is from the class')
}
}
$null = [TestClass]::new()
There are two dialogs shown when I use Powershell ISE however I got an error when I've run ps-script through cmd
>powershell.exe -file ClassTest.ps1
At D:\ClassTest.ps1:7 char:10
+ [System.Windows.MessageBox]::Show('MessageBox is from the cla ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
Unable to find type [System.Windows.MessageBox].
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : TypeNotFound
How can I get a MessageBox dialog correctly?
P.S. Win10, Powershell 5.1.19041.1320