首页 > 解决方案 > 在没有提示的情况下在 powershell 中获取 Office 365 凭据

问题描述

我想使用 powershell 自动将文件从 Sharepoint 下载到本地磁盘,但我不希望我的用户输入密码,因为脚本将在每次系统启动时运行。

Windows 密码与 Office 365 的密码相同,所以我可以使用这个密码,有什么技巧可以在 PS 中实现吗?

标签: windowsazurepowershelloffice365

解决方案


您可以使用 DefaultNetworkCredentials

 $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl) 
 $ctx.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
 $web = $ctx.Web
 $ctx.Load($web);
 $ctx.ExecuteQuery();

推荐阅读