【问题标题】:My powershell script can't delete multiple users from csv file but can delete 1 user我的 powershell 脚本无法从 csv 文件中删除多个用户,但可以删除 1 个用户
【发布时间】:2022-10-13 15:35:55
【问题描述】:

这是删除用户的脚本,但前提是 csv 文件中有 1 个条目。但是,当我在 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

【问题讨论】:

  • foreach 循环有项目变量$Files,但你从不使用它。这是复制粘贴错误还是实际代码?
  • 那是实际代码..那我应该在那里使用什么?
  • 没关系..我解决了..版本-foreach($CSVFile中的$files){foreach($files.users中的$line){$user = $line
  • 我认为这样更好,将原始脚本中的$user = $CSVFile.users 替换为$user = $Files.users

标签: powershell csv sharepoint sharepoint-2013 powershell-4.0


【解决方案1】:

请尝试更改代码“$user = $CSVFile.users“ 至 ”$user = $Files.users“。希望它可以帮助你。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-13
    • 1970-01-01
    • 2021-12-30
    相关资源
    最近更新 更多