0
votes

I am trying to generate a text file with output I need to build in a for each statement but I get this error:

add-content : 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.

What am I missing here?

foreach($item in $filteredItems)
{
    $user = $web.EnsureUser($item)
    if (-Not $profileManager.UserExists($user.LoginName))
    {
        $loginName = $user.LoginName.Substring(13)
        #Write-Host $loginName
        $userFromAD = Get-ADUser -Filter {SAMAccountName -eq $loginName}
        $concatenatedUser = $user.ID.ToString() + ";#" + $userFromAd.Name
        #Write-Host  $concatenatedUser
        $query = [String]::Format("<Where><Contains><FieldRef Name='Persons_PDB' LookupId='True'/><Value Type='LookupMulti'>{0}</Value></Contains></Where>",$user.ID)
        $userItemsQuery = New-Object Microsoft.SharePoint.SPQuery
        $userItemsQuery.Query = $query
        $userItemsQuery.ViewAttributes = 'Scope="Recursive"'
        $userItems = $list.GetItems($userItemsQuery)
        #Write-Host "Numer of items found: " $userItems.Count
        foreach($item in $userItems)
        {
            #Write-Host $userFromAd.Name
            if([string]::IsNullOrEmpty($userFromAd.Name)){
                $output = "Person not in AD, file will be deleted:"+ $item.File.Name 
                write-output $output | add-content D:\Installers\PictureDB\R 1.0\Scripts\Add-ArtifactsToWeb\usernotinAD.txt
            }
1
Hi you can try out-file -Append ? i think this can be work at you want docs.microsoft.com/en-us/powershell/module/… or other way you can try add " " to the file path name - Sanpas

1 Answers

3
votes

You are having space in your path and PS is not able to pick it up. Also, write-output will display the output directly in the terminal and will not pass it to the pipeline object. I have modified it accordingly. I am not going through the logic that you have put together since you are getting issue only on the output part of it.

Change this:

write-output $output | add-content D:\Installers\PictureDB\R 1.0\Scripts\Add-ArtifactsToWeb\usernotinAD.txt

To:

$output | add-content "D:\Installers\PictureDB\R 1.0\Scripts\Add-ArtifactsToWeb\usernotinAD.txt" -Force

Hope it helps.