I'm new to scripting and have run into an issue. What we are trying to accomplish is for all our of SharePoint sites listed in a file, we want to gather a list of Users, compare them to the Admin array, then if they do not exist in the array, clear their permissions and add them back as Read only.
$ListofSites = Get-Content -Path "C:\sites.txt"
$AdminUserLogin = @("DOMAIN\USER", "DOMAIN\USER2",
)
foreach ($item in $ListofSites)
{
Write-Host $item
$Users = Get-SPUser -Web $item -Limit ALL | Format-Table -AutoSize
foreach ($user in $Users)
{
Write-Host $user
If ($user -ne $AdminUserLogin) {Set-SPUser -Identity $._UserLogin -ClearPermissions -AddPermissionLevel 'Read'}
Else {"User is an admin"}
}
}I am getting this error--seems to be a piping error but I'm not really sure! Help please!
Set-SPUser : The parameterless Read method can only be used when this instance was initialized with an SPUser object.At C:\Scripts\SPReadOnly2.ps1:30 char:55
+ If ($user -ne $AdminUserLogin) {Set-SPUser <<<< -Identity $._UserLogin -ClearPermissions -AddPermissionLevel 'Read'}
+ CategoryInfo : InvalidData: (Microsoft.Share...SPCmdletSetUser:SPCmdletSetUser) [Set-SPUser], InvalidOperationException
+ FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletSetUser