powershell - 查找超过 SharePoint 400 个字符限制的路径
问题描述
我们最近迁移到在线 SharePoint 并发现我们的一些路径正在获取损坏的文件,因为它们超过了 SharePoint 设置的 400 个字符的限制。我只是我们特定站点的管理员,而不是我们 SharePoint 租户的全局管理员,因此尝试使用 SharePoint 的 PowerShell 集成不起作用。我还尝试在资源管理器视图中查看并从那里运行 PowerShell 以查找任何内容 -gt 400,但存在 Windows 限制,即在出现错误之前只能找到最多 248 个字符的路径。有没有人遇到过这个问题或知道任何解决方法?
我曾尝试将模块SharePointPnPPowerShellOnline
与 PowerShell 一起使用,但由于我不是全局管理员而出现禁止错误。我还尝试在 Windows 资源管理器视图中递归查看,但出现错误。
这是尝试在 Windows 资源管理器视图中执行此操作时出现的错误:
Get-ChildItem :指定的路径、文件名或两者都太长。完全限定文件名必须少于 260 个字符,目录名必须少于 248 个字符
解决方案
您是否考虑过使用 SharePoint 在线 CSOM?你可以使用这个 nuget -> SharePointPnP
有了这个,您可以实现任何类型的应用程序(如控制台应用程序)并获取所有文件夹中的所有文件夹、文件和文件,并获取它们的名称、路径或所需的任何内容,并检查它是否超过 400 个字符。(请记住,像 FileServerRelativeUrl 这样的附加列需要在上下文中加载)
try
{
string siteUrl = "SiteURL";
AuthenticationManager authManager = new AuthenticationManager();
using (ClientContext context = authManager.GetWebLoginClientContext(siteUrl))
{
List list = context.Web.Lists.GetByTitle("LibName");
context.Load(list);
context.Load(list.RootFolder);
context.Load(list.RootFolder.Folders);
context.Load(list.RootFolder.Files);
context.ExecuteQuery();
FolderCollection folderCol = list.RootFolder.Folders;
foreach (Folder f in folderCol)
{
context.Load(f.Files);
context.ExecuteQuery();
FileCollection innerFileCol = f.Files;
foreach (File file in innerFileCol)
{
//var x = file.Name;
// ToDo other logic here
}
}
FileCollection fileCol = list.RootFolder.Files;
foreach (File file in fileCol)
{
//var x = file.Name;
// ToDo other logic here
}
}
}
catch (Exception ex)
{
// log error
throw;
}
我希望它会有所帮助:)
推荐阅读
- sql-server - 有没有更好的方法在 SQL Server 的名称字段中查找不正确的大写/小写单词?
- javascript - 将一个数组拆分为 2 个按对象属性分组的数组
- tensorflow - od_graph_def = tf.GraphDef() AttributeError: 模块 'tensorflow' 没有属性 'GraphDef'
- docker - 安装过程中权限被拒绝错误 使用 docker “生成服务器配置文件”的第 1 步
- android - Mockito.doNothing 不适用于 Handler
- vb.net - 尝试将 excel 文件加载到 .net (web) 中的数据表时请求 Veracode CWE 89 帮助
- javascript - 如何将单选按钮的值保存到本地存储?如何恢复它?
- amazon-s3 - 使用 localstack 从 s3 调用 lambda 的问题
- arrays - 从 Numpy 数组中删除值
- python - 如何使用 python 3.7.4 在 Windows 上使用 pip 安装烧瓶并安装 pip?