Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.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
在某些SharePoint网站上执行自动登录的PowerShell脚本_Powershell_Sharepoint - Fatal编程技术网

在某些SharePoint网站上执行自动登录的PowerShell脚本

在某些SharePoint网站上执行自动登录的PowerShell脚本,powershell,sharepoint,Powershell,Sharepoint,这是我写的脚本: 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

这是我写的脚本:

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&lt;=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)
$postParams=”
;tagName=A;id=linkTurnOnAcc;title=打开更易访问的模式;href=#;class=ms-accessible-ms-acc按钮;onclick=SetIsAccess
ibilityFeatureEnabled(true);UpdateAccessibilityUI();document.getElementById('linkTurnOffAcc').focus();return false;},@{outerHTML=;tagName=A;id=linkTurnOffAcc;title=关闭更易访问模式;href=#;class=ms易访问ms acc按钮;onclick=SetIsAccess
ssibilityFeatureEnabled(false);UpdateAccessibilityUI();document.getElementById('linkTurnOnAcc').focus();return false;},@{outerHTML=;tagName=A;href=javascript:;;title=Skip Ribbon命令;onclick=document.getElementById('startNavigation').focus();class=ms
-可访问的ms acc按钮;accesskey=Y},@{outerHTML=;标记名=A;href=javascript:;;title=跳到主要内容;onclick=document.getElementById('mainContent').focus();class=ms acc
essible ms acc按钮}…}
ParsedHtml:
原始内容长度:77875
图式厌恶:15.0.0.0
图书馆版本:16.0.8008.1209
ErrorInfo:@{ErrorMessage=未知错误;ErrorValue=;TraceCorrelationId=9ef1849e-f07e-6000-db7a-919a894fc2a0;ErrorCode=-1;ErrorTypeName=Microsoft.SharePoint
.Client.UnknownError}
TraceCorrelationId:9ef1849e-f07e-6000-db7a-919a894fc2a0
图式厌恶:15.0.0.0
图书馆版本:16.0.8008.1209
错误信息:
TraceCorrelationId:9ef1849e-a085-6000-ecda-ea2580e6ab26
40
IsNull:False
图式厌恶:15.0.0.0
图书馆版本:16.0.8008.1209
错误信息:
TraceCorrelationId:9ef1849e-708b-6000-ecda-e8248abbc80c
43
IsNull:False
48
IsNull:False
56
IsNull:False
59
IsNull:False
60
_对象类型:Microsoft.SharePoint.Client.Search.Query.ResultTableCollection
过期时间:215
属性:@{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=}
询问者:
查询ID:7b7f4a08-78d4-42c3-8ad1-d862545d35af
拼写建议:
TriggeredRules:{}
结果表:{@{u 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=
相关结果;TotalRows=68;TotalRows包含重复项=68}
我认为只放前三个请求可能是错误的,因为当我按下按钮时,有220个请求正在发布(此按钮打开附加菜单而不重新启动页面)。在开始时,我只放了一个请求,其中包含带所需参数的字符串(这是一个 42eb6ca1-4B8-42d3-b502-c2f69525c8d4 以**$postParams2为单位**
PowerShell未报告任何错误,但脚本不起作用。

不确定如何解决问题,但如果您选择这些大XML字符串,可能会更容易。您不必转义所有这些双引号。
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:&quot;https://oriflamegroup.sharepoint.com/News/Pages&quot; OR Path:&quot;https://oriflamegroup.share
                     point.com/PeopleNews/Pages&quot;) AND TheOneArticleDate&lt;=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}}
Type=`"String`">42eb6ca1-4bb8-42d3-b502-c2f69525c8d4</Parameter>

  in **$postParams2**