I have a script that when I run locally on my domain controller it works fine without issues (using Import-Module ActiveDirectory
locally instead of a remote PSSession). However, when I run it remotely it fails with the following error:
The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input. + CategoryInfo : InvalidArgument: (CN=Test User ...,DC=domain,DC=com:PSObject) [Get-ADUser], ParameterBindingException + FullyQualifiedErrorId : InputObjectNotBound,Microsoft.ActiveDirectory.Management.Commands.GetADUser + PSComputerName : van-dc03.vand1.oppy.com
The code I am running is:
$ADSession = New-PSsession -ComputerName ourdcserver -Credential $(Get-Credential)
Invoke-Command -Command {
Import-Module ActiveDirectory,AdSync -Cmdlet Get-ADUser, Search-ADAccount
} -Session $ADSession
Import-PSSession -Session $ADSession -AllowClobber -Module ActiveDirectory
Search-ADAccount -UsersOnly -AccountInactive -SearchBase "OU=test,DC=our,DC=domain,DC=com" -Timespan 30.00:00:00 |
Where-Object { $_.Enabled -eq $true } |
Get-ADUser -Properties Name, sAMAccountName, WhenCreated, lastLogonTimestamp |
Select Name, sAMAccountName, WhenCreated,
@{n="LastLogonTimeStamp";e={[DateTime]::FromFileTime($_.LastLogonTimestamp)}} |
Sort-Object LastLogonTimeStamp |
Export-CSV $CurrentWorkfile -NoTypeInformation -Encoding ASCII
I found a similar thread on this Technet forums thread however I am not very familiar with PowerShell. Anyone able to give me a hand re-writing this code (or an example) so that the piping works?
`
followed by the command starting at next line. I think if you'll keep your Search-ADAccount query in one line in editor, it'd work! – Am_I_Helpful