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
}