I can run sections of the code in the powershell editor and retrieve data so it seems to be an environment problem. I just don’t know where to start. Not sure how to change the run as credentials as my SQL DB is using trusted connection.
If anyone can point me in the right direction I’d be very grateful.
@dalef
your issue is the dbatools module is not loaded in PSU thats why you see the message command not recognized
what you need to do is to add the dbatools module in the admin screen under the environment you are using to be loaded when you run psu as below
Thanks, that makes sense. I didn’t realise I had to add them manually. OK, so I type in dbatools and hit save but when I check it it’s not there - it doesn’t save. Am I missing something?
@dalef
The problem with integrated env before the latest release it was not loading the windows powershell modules so adam fixed that issue in the latest release.
but in your case if you are using integrated env try to add the full path of dbatools just by itself first or the module name only to check if your issue resolved before adding anything else.
another solution is to look for psu folder and locate the modules folder there and add the dbatools folder to the rest of the moules there and test.
you can also in you script before running the query line add the following line to the path of the dbatools
import-module <path to dbatools module> -force
invoke-dbaquery ....
Many thanks. I’ll give those options a try. By the way, should I prefer one environment over another? All my scripts work in 5.1 and 7.2 so should I target those? What’s the “integrated” aspect of the Integrated environment - does it use both?
The integrated environment runs directly within the PSU process rather than starting an external process. If you are using PSU v2, it’s using PowerShell version 7.1.