这是删除用户的脚本,但只有当1条目在那里的csv文件。然而,当我在csv中输入多个条目,脚本将所有行的值作为一个单一的条目。我该如何修复它?提前感谢!
Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue
$CSVPath = "D:\Temp\userss.csv"
$CSVFile = Import-CSV $CSVPath
$web = Get-SPWeb -Identity https://................./
$DocLibsName = "Bilder der websitesammlung"
$folder = $web.Folders[$DocLibsName].SubFolders
foreach($Files in $CSVFile)
{
Write-Host "Retreiving user..." -ForegroundColor Blue
$user = $CSVFile.users
$items = $folder.Files | where {$_.Title -eq $user}
If($items.Title -contains $user)
{
$items.Delete()
Write-Host $user "deleted" -ForegroundColor DarkGreen
}
Else {
Write-Host $user"not found" -ForegroundColor DarkRed
}
}
Write-Host "Finished" -ForegroundColor Green
2条答案
按热度按时间kmpatx3s1#
请尝试将代码“$user = $CSVFile.users”更改为“$user = $Files.users"。希望它能对您有所帮助。
t3irkdon2#
请尝试使用以下PowerShell代码: