This is my script:
Add-Type -Path C:\MyClassLibrary\HidClassLib.dll
$hidDevice = New-Object HidClassLib.CAN_USBPort("test")
$hidDevice.openPort()
When I run this script from the command line in PowerShell ISE it runs properly and adds the HidClassLib.dll to my path.
The $hidDevice variable doesn’t persist however, and before I can use it I have to retype those two lines. Is there any way to make it so that the $hidDevice would persist after running the script?
You mean that it doesn’t persist between sessions? In that case, add it to your PowerShell profile!
Here’s a great article on how to do that:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb613488(v=vs.85).aspx
Just add the line(s) to the applicable profile and it will run every time a shell opens.