我有一个关于Sitecore Powershell Extensions的好奇案例。我创建了一个基于.net的Cmdlet,我可以在使用带有必需参数的import命令后执行它。 现在我想通过在外部系统中安排它来自动化这个cmdlet,因为我不信任Sitecore调度程序。因此,我在Sitecore中使用ISE编写了一个新函数,并保存为' Powershell Script'项目。 以下是代码:
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&amp; PowerShellWebService.asmx但没有用,并且关于相同的文档非常少。 例如,我试图编写Windows PS文件,我可以在Job服务器或任何其他调度程序中安排,因为大多数支持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
请指导我错在哪里..
答案 0 :(得分:1)
您是否尝试过应用this post on my blog?
中的解决方案它应该允许您在服务器上执行任意脚本块。
答案 1 :(得分:0)
从那时起,我们发布了一个SPE Remoting模块,您可以在本地计算机上使用该模块与Sitecore的远程实例进行交互。
在这里阅读更多相关信息: https://sitecorepowershell.gitbooks.io/sitecore-powershell-extensions/content/remoting.html