I have a .psm1 module in my default powershell module path. I create a class in it but for some reason it doesn't respect my "Add-Type"
#file: MyTest.psm1
Class MyWinUtils
{
Static [Void] MoveMouse([Int]$x, [Int]$y)
{
Add-Type -AssemblyName System.Windows.Forms
Add-type -AssemblyName System.Drawing
[System.Windows.Forms.Cursor]::Position = `
New-Object System.Drawing.Point( $x, $y)
#Write-Host "Move Mouse to x=$x y=$y"
}
Static [Void] GetMousePosition()
{
$X = [System.Windows.Forms.Cursor]::Position.X
$Y = [System.Windows.Forms.Cursor]::Position.Y
Write-Host "X: $X | Y: $Y"
}
}
Then I did below in command line: using module MyTest
The error message is
+ [System.Windows.Forms.Cursor]::Position = `
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unable to find type [System.Windows.Forms.Cursor].
I also tried to move the Add type to the beginning of the psm1 file the same error Can you please shed some light on it?