locked
Powershell Script RRS feed

  • Question

  • Greetings;

    I am trying to run the following script on my server and keep getting an error. I am hoping to get some assistance with this. The script is as follows:

    #Load SharePoint 2007 Assemblies

    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") >null


    $siteUrl= "https://webapplicationurl"
    $site=new-object Microsoft.SharePoint.SPSite($siteURL)

    #Enter the date you want to compare, leave the date blank if you want the current date.
    $date = Get-Date 6/1/2017

    foreach($web in $site.AllWebs)
    {
         "Site " + $web.Url >> c:\temp\LastModified.txt
       
        foreach($list in $web.Lists)
        {
            if($list.LastItemModifiedDate -gt $date) #if list item modified date is greater than $date write to text file
            {
                "-List" + $list.Title >> c:\temp\LastModified.txt
                "——Last Modified" + $list.LastItemModifiedDate >> c:\temp\LastModified.txt
            }
        }
    web.Dispose()
    }
    site.Dispose()

    The error I am getting is:

    New-Object : Exception calling ".ctor" with "1" argument(s): "The Web application at https://webapplicationurl
    .ca could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, th
    e system administrator may need to add a new request URL mapping to the intended application."
    At line:1 char:17
    + $site=new-object <<<<  Microsoft.SharePoint.SPSite($siteURL)
        + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException
        + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

    Please help if you can

    Thanks Kim

    Tuesday, July 11, 2017 3:20 PM

All replies

  • It seems like the URL you are trying to give to the command is invalid. Can you confirm the URL you are entering in

    """

    $siteUrl= "https://webapplicationurl"

    """

    is valid? 

     

    If you find an answer has helped you please use the answer button and/or use that thumbs up! Julio Sanchez-Tirado http://scriptomato.com co-founder | CEO | Pitcher

    Wednesday, July 12, 2017 10:27 AM
  • Good Morning Sanchez.

    I am 150%sure that this url is correct. Any other suggestions?

    Kim

    Wednesday, July 12, 2017 12:24 PM
  • I have found a simiar case, you can find it here.

    """

    One of the cause of this error is that the user using which you are running the code is not in the WSS_ADMIN_WPG group. Follow these steps to add the user into this group.

    1. Go to Computer Management
    2. Open Users and Group section
    3. Double click on WSS_ADMIN_WPG group
    4. Add the user into this group

    Hope this helps you.

    """

    Can you check if this works?


    If you find an answer has helped you please use the answer button and/or use that thumbs up! Julio Sanchez-Tirado http://scriptomato.com co-founder | CEO | Pitcher

    Wednesday, July 12, 2017 1:45 PM
  • Hello,

    in case Julio's answer didn't solved your issue, you may take a look a this post : https://blog.sharepointrx.com/2009/08/26/the-web-application-at-url-could-not-be-found-verify-that-you-have-typed-the-url-correctly-if-the-url-should-be-serving-existing-content-the-system-administrator-may-need-to-add-a-new-request-url/

    Weird stuff but remove the account from SCA and add it again fix it for him..


    Best regards, Christopher.
    Blog | Mail
    Please remember to click "Mark As Answer" if a post solves your problem or "Vote As Helpful" if it was useful.
    Why mark as answer?

    Wednesday, July 12, 2017 1:53 PM
  • Hi Julio - The user is already in the group, so this can not be the problem.

    Thanks

    Kim

    Wednesday, July 12, 2017 2:43 PM