WindowsCompatibility icon indicating copy to clipboard operation
WindowsCompatibility copied to clipboard

Variables are not passed to Filter parameter of any cmdlet from ActiveDirectory module

Open kborowinski opened this issue 6 years ago • 3 comments

Variables are not passed to Filter parameter on any cmdlet from ActiveDirectory module imported through Import-WinModule:

variables

Workaround: Use string formatting operator

kborowinski avatar Aug 07 '18 10:08 kborowinski

When I try to import 'import-WinModule' I get access denied. "cannot validate argument on parameter 'session'. @kborowinski were you able to get past this and if so, how?

justinhauer avatar Aug 26 '18 22:08 justinhauer

@jdogg89: I was using an elevated Powershell 6.1.0 console on Windows 7 to import ActiveDirectory module.

kborowinski avatar Aug 27 '18 11:08 kborowinski

The script block gets evaluated in the remote scope which will not have your local scope variables in it. I would highly recommend using string evaluated in the local scope for -Filter for a multitude of reasons beyond compatibility with this module.

Try

Get-AdComputer -Filter "Name -like 'PS*' -and LastLogonTimeStamp -lt '$time'"

markekraus avatar Oct 01 '18 23:10 markekraus