Forum Discussion
AD cmdlets not working
I'm trying to locate users in Active Directory using a function. When I run the code in either ISE or Visual Studio Code, the lookup works. When I run the script in a PowerShell window the lookup doesn't work. Has anyone seen this before and know what the solution is?
4 Replies
- LainRobertsonSilver Contributor
Hi, Walter.
Does the PowerShell window provide any error, warning or information messages?
What edition of PowerShell is running in the ISE, VS Code and the separate window? Windows PowerShell (5.x) or Powershell (7.x)?
Cheers,
Lain
- wpinedoCopper ContributorNo messages. I'm using the ISE to test version 5.x and VS Code to test version 7.x and they both work. Using both a 5.x or a 7.x window doesn't.
- LainRobertsonSilver Contributor
One other possibility - and it's so obvious I should have thought of it first, is that the PowerShell window session may not be able to see the module.
I don't know what Active Directory commands you're running as we have no example from you, but you can use Get-Command to see if the commandlet is resolvable:
Get-Command <Active Directory module commandlet>
For example:
Get-Command -Name Get-ADObject;
If you get nothing back from that, then your issue is that the PowerShell session does not know about the ActiveDirectory module.
This can be corroborated by running:
Get-Module -ListAvailable ActiveDirectory;
Cheers,
Lain