Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PowerShell从流行趋势(Sharepoint Online)中提取使用情况报告_Powershell_Sharepoint_Sharepoint 2013_Office365 - Fatal编程技术网

使用PowerShell从流行趋势(Sharepoint Online)中提取使用情况报告

使用PowerShell从流行趋势(Sharepoint Online)中提取使用情况报告,powershell,sharepoint,sharepoint-2013,office365,Powershell,Sharepoint,Sharepoint 2013,Office365,几天前,我试图从我的Sharepoint Online检索所有网站的使用情况报告,但由于我们有太多的网站,因此在下载.xlsx报告的链接后访问链接很难获取所有网站。然后我开始编写PowerShell脚本来提取这些内容 但出于某种原因,当我的代码开始下载文件时,它会下载O365登录页面的HTML代码。这表明该应用程序正在丢失会话,因为它在前一刻已经连接到该站点,突然我以一个登录页面结束。虽然我不知道如何解决这个问题 这是尝试下载使用情况报告的代码部分: # Usage Reports for Pr

几天前,我试图从我的Sharepoint Online检索所有网站的使用情况报告,但由于我们有太多的网站,因此在下载.xlsx报告的链接后访问链接很难获取所有网站。然后我开始编写PowerShell脚本来提取这些内容

但出于某种原因,当我的代码开始下载文件时,它会下载O365登录页面的HTML代码。这表明该应用程序正在丢失会话,因为它在前一刻已经连接到该站点,突然我以一个登录页面结束。虽然我不知道如何解决这个问题

这是尝试下载使用情况报告的代码部分:

# Usage Reports for Prod 
$Usage       = $UsageGUID 

# set the file path and name 
$filename = $path + (Get-Variable $searchreport).Name + ".xlsx" 
$reportid = (Get-Variable $searchreport).Value

$TTNcontent = "javascript:ResetSpFormOnSubmitCalled();__doPostBack('__Page','ReportId=" + $reportid + "')"

# setup the WebRequest    
[net.httpWebRequest] $webRequest = [net.webRequest]::create($url)
$webRequest.Credentials = $SPOCredentials
$webRequest.CookieContainer = New-Object System.Net.CookieContainer
$webRequest.Accept = "image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, application/x-ms-xbap, */*"    
$webRequest.ContentType = "application/x-www-form-urlencoded" 
$webRequest.Method = "POST"
$webRequest.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko"

$encodedContent = [System.Text.Encoding]::UTF8.GetBytes($TTNcontent) 
$webRequest.ContentLength = $encodedContent.length 
$requestStream = $webRequest.GetRequestStream() 
$requestStream.Write($encodedContent, 0, $encodedContent.length) 
$requestStream.Close()

#The problem occurs on this step: Once GetResponse is fired, instead of getting the .xlsx as a response, it downloads the HTML of the O365 authentication screen
#My guess is that the application is losing the login session before the .GetResponse() but I don't know how/why...
[net.httpWebResponse] $resp = $webRequest.GetResponse();    
$rs = $resp.GetResponseStream();  
[System.IO.BinaryReader] $sr = New-Object System.IO.BinaryReader -argumentList $rs; 
[byte[]]$results = $sr.ReadBytes(10000000);

# write the file 
Set-Content $filename $results -enc byte
以下是完整的代码文件:

有什么想法或建议吗

提前感谢:)

马可