1

This is somewhat SharePoint related, but I think the essence of the question is not actually SharePoint specific.

Here's the situation. I'm using a third party SharePoint add-on. When this add-on is installed, it provides a link in the SharePoint Library Settings page for record libraries. If you click on the link, it executes some code and does some configuration to the library (installs custom content types, etc.).

The link itself executes some Javascript:

function dialogCallback()
{
    SP.UI.Notify.addNotification('Content types installed and settings configured.');                                                        
    SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);
}
function openInstallContentTypesDialog()
{ 
    var options = SP.UI.$create_DialogOptions();
    options.url = 'http://my.sharepoint.site/_layouts/Custom/Feature/ExecuteConfigurationCode.aspx?SiteUrl=http://my.sharepoint.site&ListId={6767676a-0101-b4dc-a67a-67a67a67a67a}';
    options.dialogReturnValueCallback = Function.createDelegate(null, dialogCallback);
    SP.UI.ModalDialog.showModalDialog(options);
}                
openInstallContentTypesDialog();

I need to configure ~50 libraries, so I would rather not have to go through the UI into each library's settings page and click that link. (Especially since I will have to do it more than once, as I set up the farm on multiple dev/test/etc environments.) I'd rather write a Powershell script, cycle through all the libraries, and somehow simulate clicking that link and calling the ExecuteConfigurationCode.aspx page. I know I can get the information needed for the query string (site url and list ID) through Powershell, but I can't figure out how to get the aspx page's code to fire.

I did some digging around, and found some posts that say to use a System.Net.WebClient object and call DownloadString() on it. Something like:

$web = get-spweb http://my.sharepoint.site
$list = $web.Lists["My Record Library"]
$requestUrl = $web.Url+"/_layouts/Custom/Feature/ExecuteConfigurationCode.aspx"
$querystring = new-object system.collections.specialized.namevaluecollection
$querystring.Add("SiteUrl", $web.Url)
$querystring.Add("ListId", "{"+$list.Id.Tostring()+"}")
$webclient = new-object system.net.webclient
$webclient.Credentials = new-object system.net.networkcredential("Site Collection Admin", "password")
$webclient.QueryString = $querystring
$response = $webclient.downloadstring($requestUrl)

And, although I do get all of the HTML that would comprise the page, the code behind the aspx page is not executed.

I have also tried the UploadString() method to see if it needs to be a POST. That had the same result -- all the HTML of the page was returned to me, but the server side code of the aspx page was not executed.

So... how can I simulate clicking that link through Powershell? (Also keep in mind that since it is SharePoint, I'm using the SharePoint 2010 Management Shell, which is Powershell 2.0. So I can't use the Invoke-WebRequest cmdlet.)

4

1 回答 1

0

您是否尝试使用 IE COM 对象:

  $url = "http://blabla/"
  $ie = New-Object -com InternetExplorer.Application
  $ie.visible = $true; 
  $ie.navigate($url); 

  $ie.Document.getElementByID("a_componenent_id").value="blabla"

  $ie.Document.getElementById("A_Form").submit()
or
  $button = $ie.Document.getElementsByTagName("input")
  $button.item(0).Click()
于 2013-09-28T06:51:05.840 回答