这是我写的脚本:
PS C:\WINDOWS\system32> Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
function Connect-SPO ([string] $Username, [string]$Password, [string]$Url) {
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($Url)
$Context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $(ConvertTo-SecureString -AsPlainText $Password -Force))
$Context.ExecuteQuery()
$AuthenticationCookie = $Context.Credentials.GetAuthenticationCookie($Url, $true)
$WebSession = New-Object Microsoft.PowerShell.Commands.WebRequestSession
$WebSession.Credentials = $Context.Credentials
$WebSession.Cookies.SetCookies($Url, $AuthenticationCookie)
$FormsDigest = $Context.GetFormDigestDirect()
$WebSession.Headers['X-RequestDigest'] = $FormsDigest.DigestValue
$Context.Dispose()
return $WebSession
}
$username = "dasha@beautyline.com"
$password = "12345"
$doclib = "Documents"
$url = "https://oriflamegroup.sharepoint.com/"
$Session = Connect-SPO -Username $Username -Password $Password -Url $Url
Invoke-WebRequest -Uri $Url -Method get -WebSession $Session -UseBasicParsing
以下是我从浏览器的开发人员工具中的前三个“ POST-Method ProcessQuery application \ json”中获取的信息,然后我自己完成了固定工作
$postParams = "<Request xmlns =`"http://schemas.microsoft.com/sharepoint/clientquery/2009`" SchemaVersion=`"15.0.0.0`" LibraryVersion=`"16.0.0.0`" ApplicationName=`"Javascript Library`">
<Actions>
<ObjectPath Id=`"37`" ObjectPathId=`"36`" />
<Method Name=`"Follow`" Id=`"38`" ObjectPathId=`"36`">
<Parameters>
<Parameter TypeId=`"{700a3260-5afb-4cf9-b401-a8e1f2c89efc}`">
<Property Name=`"AccountName`" Type=`"Null`" />
<Property Name=`"ActorType`" Type=`"Number`">2</Property>
<Property Name=`"ContentUri`" Type=`"String`">https://oriflamegroup.sharepoint.com/russia</Property>
<Property Name=`"Id`" Type=`"Null`" />
<Property Name=`"TagGuid`" Type=`"Null`" />
</Parameter>
</Parameters>
</Method>
</Actions>
<ObjectPaths>
<Constructor Id=`"36`" TypeId=`"{651f2511-b4a4-4c3d-8c12-b049c7f79d69}`" />
</ObjectPaths>
</Request>"
$postParams2 = "<Request xmlns =`"http://schemas.microsoft.com/sharepoint/clientquery/2009`" SchemaVersion=`"15.0.0.0`" LibraryVersion=`"16.0.0.0`" ApplicationName=`"Javascript Library`">
<Actions>
<ObjectPath Id=`"40`" ObjectPathId=`"39`" />
<Method Name=`"SetSingleValueProfileProperty`" Id=`"41`" ObjectPathId=`"39`">
<Parameters>
<Parameter Type=`"String`">i:0#.f|membership|dasha@beautyline.com</Parameter>
<Parameter Type=`"String`">TheOnePinnedMarkets</Parameter>
<Parameter Type=`"String`">42eb6ca1-4bb8-42d3-b502-c2f69525c8d4</Parameter>
</Parameters>
</Method>
</Actions>
<ObjectPaths>
<Constructor Id=`"39`" TypeId=`"{cf560d69-0fdb-4489-a216-b6b47adf8ef8}`" />
</ObjectPaths>
</Request>"
$postParams3 = "<Request xmlns =`"http://schemas.microsoft.com/sharepoint/clientquery/2009`" SchemaVersion=`"15.0.0.0`" LibraryVersion=`"16.0.0.0`" ApplicationName=`"Javascript Library`">
<Actions>
<ObjectPath Id=`"43`" ObjectPathId=`"42`" />
<SetProperty Id=`"44`" ObjectPathId=`"42`" Name=`"QueryText`">
<Parameter Type=`"String`">(ContentTypeId:'0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D000AE327FB078F4152BC1B1E06AC166F2D*' OR ContentTypeId:'0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D003CE1DA6E578F4F1888467D1CFE4E88B4*') AND oriflameFeaturedOWSBOOL:1 AND (Path:`"https://oriflamegroup.sharepoint.com/News/Pages`" OR Path:`"https://oriflamegroup.sharepoint.com/PeopleNews/Pages`") AND TheOneArticleDate<=2018-08-15T07:47:00.592Z</Parameter>
</SetProperty>
<SetProperty Id=`"45`" ObjectPathId=`"42`" Name=`"TrimDuplicates`">
<Parameter Type=`"Boolean`">true</Parameter>
</SetProperty>
<SetProperty Id=`"46`" ObjectPathId=`"42`" Name=`"RowLimit`">
<Parameter Type=`"Number`">10</Parameter>
</SetProperty>
<ObjectPath Id=`"48`" ObjectPathId=`"47`" />
<Method Name=`"Add`" Id=`"49`" ObjectPathId=`"47`">
<Parameters>
<Parameter Type=`"String`">PublishingImage</Parameter>
</Parameters>
</Method>
<Method Name=`"Add`" Id=`"50`" ObjectPathId=`"47`">
<Parameters>
<Parameter Type=`"String`">TheOneArticleDate</Parameter>
</Parameters>
</Method>
<Method Name=`"Add`" Id=`"51`" ObjectPathId=`"47`">
<Parameters>
<Parameter Type=`"String`">Title</Parameter>
</Parameters>
</Method>
<Method Name=`"Add`" Id=`"52`" ObjectPathId=`"47`">
<Parameters>
<Parameter Type=`"String`">CommentsOWSMTXT</Parameter>
</Parameters>
</Method>
<Method Name=`"Add`" Id=`"53`" ObjectPathId=`"47`">
<Parameters>
<Parameter Type=`"String`">LikesCount</Parameter>
</Parameters>
</Method>
<SetProperty Id=`"54`" ObjectPathId=`"42`" Name=`"EnableSorting`">
<Parameter Type=`"Boolean`">true</Parameter>
</SetProperty>
<ObjectPath Id=`"56`" ObjectPathId=`"55`" />
<Method Name=`"Add`" Id=`"57`" ObjectPathId=`"55`">
<Parameters>
<Parameter Type=`"String`">TheOneArticleDate</Parameter>
<Parameter Type=`"Number`">1</Parameter>
</Parameters>
</Method>
<ObjectPath Id=`"59`" ObjectPathId=`"58`" />
<Method Name=`"ExecuteQuery`" Id=`"60`" ObjectPathId=`"58`">
<Parameters>
<Parameter ObjectPathId=`"42`" />
</Parameters>
</Method>
</Actions>
<ObjectPaths>
<Constructor Id=`"42`" TypeId=`"{80173281-fffd-47b6-9a49-312e06ff8428}`" />
<Property Id=`"47`" ParentId=`"42`" Name=`"SelectProperties`" />
<Property Id=`"55`" ParentId=`"42`" Name=`"SortList`" />
<Constructor Id=`"58`" TypeId=`"{8d2ac302-db2f-46fe-9015-872b35f15098}`" />
</ObjectPaths>
</Request>"
Invoke-RestMethod 'https://oriflamegroup.sharepoint.com/russia/_vti_bin/client.svc/ProcessQuery' -Method POST -Body $postParams -ContentType 'application/json' -WebSession $Session #-Headers $headers)
Invoke-RestMethod 'https://oriflamegroup.sharepoint.com/russia/_vti_bin/client.svc/ProcessQuery' -Method POST -Body $postParams2 -ContentType 'application/json' -WebSession $Session #-Headers $headers)
Invoke-RestMethod 'https://oriflamegroup.sharepoint.com/russia/_vti_bin/client.svc/ProcessQuery' -Method POST -Body $postParams3 -ContentType 'application/json' -WebSession $Session #-Headers $headers)
这是控制台的答案
StatusCode : 200
StatusDescription : OK
Content : 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html dir="ltr" lang="en-GB">
<head><meta name="GENERATOR" content="Microso...
RawContent : HTTP/1.1 200 OK
X-SharePointHealthScore: 2
SPRequestGuid: 9ef1849e-7035-6000-39d0-196b2bb7b26a
request-id: 9ef1849e-7035-6000-39d0-196b2bb7b26a
MS-CV: noTxnjVwAGA50BlrK7eyag.0
Strict-Transport-Se...
Forms :
Headers : {[X-SharePointHealthScore, 2], [SPRequestGuid, 9ef1849e-7035-6000-39d0-196b2bb7b26a], [request-id, 9ef1849e-7035-6000-39d0-196b2bb7b26a], [MS-CV, noT
xnjVwAGA50BlrK7eyag.0]...}
Images : {@{outerHTML=<img src="/_layouts/15/images/spcommon.png?rev=44#ThemeKey=spcommon" />; tagName=IMG; src=/_layouts/15/images/spcommon.png?rev=44#ThemeK
ey=spcommon}, @{outerHTML=<img src="/_layouts/15/images/spcommon.png" />; tagName=IMG; src=/_layouts/15/images/spcommon.png}, @{outerHTML=<img src="/
_layouts/15/images/spcommon.png?rev=44#ThemeKey=spcommon" alt="Share" style="position:absolute;left:-200px;top:-48px;" />; tagName=IMG; src=/_layouts
/15/images/spcommon.png?rev=44#ThemeKey=spcommon; alt=Share; style=position:absolute;left:-200px;top:-48px;}, @{outerHTML=<img src="/_layouts/15/imag
es/spcommon.png?rev=44#ThemeKey=spcommon" alt="Focus on Content" style="border:0;position:absolute;left:-143px;top:-178px;" />; tagName=IMG; src=/_la
youts/15/images/spcommon.png?rev=44#ThemeKey=spcommon; alt=Focus on Content; style=border:0;position:absolute;left:-143px;top:-178px;}...}
InputFields : {@{outerHTML=<input type="hidden" name="_wpcmWpid" id="_wpcmWpid" value="" />; tagName=INPUT; type=hidden; name=_wpcmWpid; id=_wpcmWpid; value=}, @{o
uterHTML=<input type="hidden" name="wpcmVal" id="wpcmVal" value="" />; tagName=INPUT; type=hidden; name=wpcmVal; id=wpcmVal; value=}, @{outerHTML=<in
put type="hidden" name="MSOWebPartPage_PostbackSource" id="MSOWebPartPage_PostbackSource" value="" />; tagName=INPUT; type=hidden; name=MSOWebPartPag
e_PostbackSource; id=MSOWebPartPage_PostbackSource; value=}, @{outerHTML=<input type="hidden" name="MSOTlPn_SelectedWpId" id="MSOTlPn_SelectedWpId" v
alue="" />; tagName=INPUT; type=hidden; name=MSOTlPn_SelectedWpId; id=MSOTlPn_SelectedWpId; value=}...}
Links : {@{outerHTML=<a id="linkTurnOnAcc" title="Turn on more accessible mode" href="#" class="ms-accessible ms-acc-button" onclick="SetIsAccessibilityFeatu
reEnabled(true);UpdateAccessibilityUI();document.getElementById('linkTurnOffAcc').focus();return false;">
Turn on more accessible mode
</a>; tagName=A; id=linkTurnOnAcc; title=Turn on more accessible mode; href=#; class=ms-accessible ms-acc-button; onclick=SetIsAccess
ibilityFeatureEnabled(true);UpdateAccessibilityUI();document.getElementById('linkTurnOffAcc').focus();return false;}, @{outerHTML=<a id="linkTurnOffA
cc" title="Turn off more accessible mode" href="#" class="ms-accessible ms-acc-button" onclick="SetIsAccessibilityFeatureEnabled(false);UpdateAccessi
bilityUI();document.getElementById('linkTurnOnAcc').focus();return false;">
Turn off more accessible mode
</a>; tagName=A; id=linkTurnOffAcc; title=Turn off more accessible mode; href=#; class=ms-accessible ms-acc-button; onclick=SetIsAcce
ssibilityFeatureEnabled(false);UpdateAccessibilityUI();document.getElementById('linkTurnOnAcc').focus();return false;}, @{outerHTML=<a href="javascri
pt:;" title="Skip Ribbon Commands" onclick="document.getElementById('startNavigation').focus();" class="ms-accessible ms-acc-button" accesskey="Y">
Skip Ribbon Commands
</a>; tagName=A; href=javascript:;; title=Skip Ribbon Commands; onclick=document.getElementById('startNavigation').focus();; class=ms
-accessible ms-acc-button; accesskey=Y}, @{outerHTML=<a href="javascript:;" title="Skip to main content" onclick="document.getElementById('mainConten
t').focus();" class="ms-accessible ms-acc-button">
Skip to main content
</a>; tagName=A; href=javascript:;; title=Skip to main content; onclick=document.getElementById('mainContent').focus();; class=ms-acc
essible ms-acc-button}...}
ParsedHtml :
RawContentLength : 77875
SchemaVersion : 15.0.0.0
LibraryVersion : 16.0.8008.1209
ErrorInfo : @{ErrorMessage=Unknown Error; ErrorValue=; TraceCorrelationId=9ef1849e-f07e-6000-db7a-919a894fc2a0; ErrorCode=-1; ErrorTypeName=Microsoft.SharePoint
.Client.UnknownError}
TraceCorrelationId : 9ef1849e-f07e-6000-db7a-919a894fc2a0
SchemaVersion : 15.0.0.0
LibraryVersion : 16.0.8008.1209
ErrorInfo :
TraceCorrelationId : 9ef1849e-a085-6000-ecda-ea2580e6ab26
40
IsNull : False
SchemaVersion : 15.0.0.0
LibraryVersion : 16.0.8008.1209
ErrorInfo :
TraceCorrelationId : 9ef1849e-708b-6000-ecda-e8248abbc80c
43
IsNull : False
48
IsNull : False
56
IsNull : False
59
IsNull : False
60
_ObjectType_ : Microsoft.SharePoint.Client.Search.Query.ResultTableCollection
ElapsedTime : 215
Properties : @{RowLimit=10; SourceId=/Guid(8413cd39-2156-4e00-b54d-11efd9abdb89)/; CorrelationId=/Guid(9ef1849e-708b-6000-ecda-e8248abbc80c)/; WasGroupRestricted
=False; IsPartial=False; HasParseException=False; WordBreakerLanguage=en; IsPartialUpnDocIdMapping=False; EnableInterleaving=True; IsMissingUnifiedG
roups=False; Constellation=927B09; SerializedQuery=<Query Culture="en-GB" EnableStemming="True" EnablePhonetic="False" EnableNicknames="False" Ignor
eAllNoiseQuery="True" SummaryLength="180" MaxSnippetLength="180" DesiredSnippetLength="90" KeywordInclusion="0" QueryText="(ContentTypeId:'0x010100C
568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D000AE327FB078F4152BC1B1E06AC166F2D*' OR ContentTy
peId:'0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D003CE1DA6E578F4F1888467D1CFE4E88B4
*') AND oriflameFeaturedOWSBOOL:1 AND (Path:"https://oriflamegroup.sharepoint.com/News/Pages" OR Path:"https://oriflamegroup.share
point.com/PeopleNews/Pages") AND TheOneArticleDate<=2018-08-15T07:47:00.592Z" QueryTemplate="" TrimDuplicates="True" Site="623c6c3b-7c14-4fd
3-a344-570850c70d33" Web="48819f1e-e0c4-4119-87d6-92b4918a91f8" KeywordType="True" HiddenConstraints="" />}
QueryErrors :
QueryId : 7b7f4a08-78d4-42c3-8ad1-d862545d35af
SpellingSuggestion :
TriggeredRules : {}
ResultTables : {@{_ObjectType_=Microsoft.SharePoint.Client.Search.Query.ResultTable; GroupTemplateId=; ItemTemplateId=; Properties=; QueryId=7b7f4a08-78d4-42c3-8ad
1-d862545d35af; QueryRuleId=00000000-0000-0000-0000-000000000000; ResultRows=System.Object[]; ResultTitle=; ResultTitleUrl=; RowCount=10; TableType=
RelevantResults; TotalRows=68; TotalRowsIncludingDuplicates=68}}
我认为仅发出前三个请求可能是错误的,因为仅按一下按钮(此按钮会打开其他菜单而不重新启动页面)时,有220个请求正在发布。开始时,我只提出了一个请求,其中包含带有所需参数的字符串(这是一个
Type=`"String`">42eb6ca1-4bb8-42d3-b502-c2f69525c8d4</Parameter>
in **$postParams2**
PowerShell没有报告任何错误,但是脚本不起作用。