gpt4 book ai didi

powershell - 如何使用参数从远程执行Sitecore中的Powershell脚本

转载 作者:行者123 更新时间:2023-12-03 00:01:02 25 4
gpt4 key购买 nike

我对Sitecore Powershell Extensions感到好奇。我创建了一个基于.net的Cmdlet,可以在使用带有必需参数的import命令后执行该命令。
现在,我想通过在外部系统中调度该cmdlet来使其自动化,因为我不信任Sitecore Scheduler。为此,我在Sitecore中使用ISE编写了一个新功能,并保存为“Powershell脚本”项。
以下是代码:

    function Execute-Auto-Site-Backup {
<#
.SYNOPSIS
Backups the given site path while looking for delta based on last execution time.

.PARAMETER Item
Item to sync, Usually a Root Item, Need to specify Sitecore Guid of Root Item.

.PARAMETER ItemList
Specifies the list of item which need to be excluded, It is in pipe separated GUIDs.

.PARAMETER UserName
Sitecore Username for taret webservice "sitecore\admin"

.PARAMETER Password
Sitecore Password

.PARAMETER HostURL
Sitecore instance Host URL

.PARAMETER DBName
Sitecore target Database name, if not passed default is "master"

.PARAMETER LangName
Sitecore Source Language name, if not passed default is "en"

.PARAMETER IncludeChildren
Indicate if need to copy the all children till nth level of indicated root item, if not passed default is false which means it will execute for single item

.PARAMETER BackupMode
Indicate if need to create versions always or just update the existing latest version, if not passed default is true which means it will create version in the target item

.PARAMETER VersionNumber
Sitecore Version number of Item to get, Default will be the Latest if not provided. In case of multiple item it will always take latest version.

.PARAMETER LookupMode
To use History Engine, if not passed default is false which means always look in iterative mode from passed root node.

.PARAMETER DateTime
If LookupMode is History Engine than this parameter will define since when to look, ideally this is last time the backup job has run. Date Time should be in following format and as per server time zone '1/20/2015 3:30:00 PM'

.EXAMPLE
BackupMode as version(non-update) always and LookupMode is single item(non-history)

[string[]]$paracs=@("{7589EBFF-FB47-41A0-8712-E34623F5518E}","","sitecore\admin","target","http://10.0.0.5/","master","en","false","true","0","false","")

.EXAMPLE
BackupMode as version(non-update) always and LookupMode is iterative(non-history) in childrens

[string[]]$paracs=@("{7589EBFF-FB47-41A0-8712-E34623F5518E}","","sitecore\admin","target","http://10.0.0.5/","master","en","true","true","0","false","")

.EXAMPLE
BackupMode as update(non-version) always and LookupMode is iterative(non-history) in childrens

[string[]]$paracs=@("{7589EBFF-FB47-41A0-8712-E34623F5518E}","","sitecore\admin","target","http://10.0.0.5/","master","en","true","false","0","false","")

.EXAMPLE
BackupMode as update(non-version) always and LookupMode is single item(non-history)

[string[]]$paracs=@("{7589EBFF-FB47-41A0-8712-E34623F5518E}","","sitecore\admin","target","http://10.0.0.5/","master","en","false","false","0","false","")



.EXAMPLE
BackupMode as version(non-update) always and LookupMode is history(non-iterative)- most used way and preferred for automate backups

[string[]]$paracs=@("{7589EBFF-FB47-41A0-8712-E34623F5518E}","","sitecore\admin","target","http://10.0.0.5/","master","en","","true","0","true","1/20/2015 3:30:00 PM")

.EXAMPLE
BackupMode as update(non-version) always and LookupMode is history(non-iterative)

[string[]]$paracs=@("{7589EBFF-FB47-41A0-8712-E34623F5518E}","","sitecore\admin","target","http://10.0.0.5/","master","en","","false","0","true","1/20/2015 3:30:00 PM")
#>
[CmdletBinding()]
param(
[ValidateNotNullOrEmpty()]
[string]$Item,

[string]$ItemList,

[ValidateNotNullOrEmpty()]
[string]$UserName,

[ValidateNotNullOrEmpty()]
[string]$Password,

[ValidateNotNullOrEmpty()]
[string]$HostURL,

[ValidateNotNullOrEmpty()]
[string]$DBName,

[ValidateNotNullOrEmpty()]
[string]$LangName,

[string]$IncludeChildren="false",

[string]$BackupMode="true",

[string]$VersionNumber,

[string]$LookupMode="false",

[string]$DateTime
)
$path=$AppPath+"bin\PG.SharedSitecore.AssemblyTools.CoreSync.dll"
Import-Module $path -Verbose
[string[]]$paracs=@($Item,$ItemList,$UserName,$Password,$HostURL,$DBName,$LangName,$IncludeChildren,$BackupMode,$VersionNumber,$LookupMode,$DateTime)
Get-CoreSyncBackup -args $paracs
}

现在,我想从远程调用此函数,我尝试使用Powershell RemoteAutomation.asmx和PowerShellWebService.asmx,但没有用,有关此文件的文档也很少。
例如,我尝试编写Windows PS文件,该文件可以在Job Server或任何其他调度程序中调度,因为它们大多数支持powershell脚本,如下所示:
    $page=New-WebServiceProxy -Uri "http://audit.brand.com/console/services/RemoteAutomation.asmx"
$BackupFunction=@"
Execute-Script "master:/sitecore/system/Modules/PowerShell/Script Library/CoreSync/SyncorBackupFunc/";
Execute-Auto-Site-Backup "{7589EBFF-FB47-41A0-8712-E34623F5518E}" "" "sitecore\admin" "b" "http://audit.brand.com/" "master" "en" "true" "true" "" "" ""
"@
$returnVar=""
$page.ExecuteScriptBlock("sitecore\admin","b",$BackupFunction,$returnVar)
$returnvar

我也尝试了以下无效的方法
    $page=New-WebServiceProxy -Uri "http://audit.brand.com/console/services/RemoteAutomation.asmx"
$BackupFunction=@"
master:/sitecore/system/Modules/PowerShell/Script Library/CoreSync/SyncorBackupFunc/
"@
$returnVar=""
$page.ExecuteScript("sitecore\admin","b",$BackupFunction,$returnVar)
$returnvar

请指导我哪里错了..

最佳答案

您是否尝试过从this post on my blog?应用解决方案

它应该允许您在服务器上执行任意脚本块。

关于powershell - 如何使用参数从远程执行Sitecore中的Powershell脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28609633/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com