Script to bulk assign 'My Site collection' secondary administrators

Hi
Staff in my company have already logged in and created their own My Sites and when they did this it set themselves as the primary administrator but left the secondary administrator blank. I want to add spadmin to the secondary administrator role.
I know you can set the secondary My Site administrators using
Set -SPSite -identity https://my.company.org.uk/personal/jamesv -secondaryowneralias DOMAIN\spadmin
Could someone please help me put this into a loop which would cycle through all of the personal sites in that web application and then set spadmin as secondary administrator for all.
Id like to learn more about Powershell but not really sure where to look, what courses to do.. if anyone knows of any please also let me know.
Many Thanks
James

Change site collection administrators for all site collections 
Get-SPWebApplication "http://intranet.crescent.com" | Get-SPSite -Limit All | ForEach-Object { Set-SPSite $_ -OwnerAlias "<domain\user>" -SecondaryOwnerAlias "<domain\user>" }
Read more: http://www.sharepointdiary.com/2013/01/change-site-collection-primary-secondary-administrators.html#ixzz3AyBN7Taj
Please remember to mark your question as answered &Vote helpful,if this solves/helps your problem. ****************************************************************************************** Thanks -WS MCITP(SharePoint 2010, 2013) Blog: http://wscheema.com/blog

Similar Messages

  • Powershell script to count number of list and library items in site collection

    We are identifying large lists in our 2010 SP environment and I'm attempting to write code to output the total number of list items in a site collection.   I'm using the code below but it only displays column data for title and url. 
    What do I need to add so it can count the number of items in each sharepoint list and library? 
    Get-SPSite -WebApplication http://sharepoint -Limit All |
       Select -ExpandProperty AllWebs |
       Select -ExpandProperty Lists |
       Select ParentWebUrl, Title
    I'm referencing
    http://sharepointpromag.com/sharepoint/windows-powershell-scripts-sharepoint-info-files-pagesweb-parts

    Please find belwo script, it will iterarte through all the folder/Subfoder to get the item counts from all list and library, you can modify this script to run this at site collection scope:
    Note: save the script in .ps1 file and execute the script as described below to get log file, it will save the log file out.txt in seleted directory:
    e.g.PS D:\PowershellScripts> .\ListItemCount.ps1 > out.txt
    $SPWebApp = Get-SPWebApplication "http://weburl.com/"
    foreach ($SPSite in $SPWebApp.Sites)
    if ($SPSite -ne $null)
    foreach ($SPWeb in $SPSite.AllWebs)
    foreach ($list in $SPWeb.Lists)
    $ListURL = $SPWeb.url + "/" + $list.RootFolder.Url
    Write-Output $ListURL
    [Microsoft.SharePoint.SPQuery]$query = New-Object Microsoft.SharePoint.SPQuery
    #$query.Folder = fldr;
    #Recursive Scope....
    $query.ViewAttributes = "Scope='Recursive'"
    $allitems = $list.GetItems($query);
    $filecount = $allitems.Count;
    Write-Output " No of item: " $filecount
    if ($SPWeb -ne $null)
    $SPWeb.Dispose()
    if ($SPSite -ne $null)
    $SPSite.Dispose()
    You can update the code to get any specific list type item count, using if($list.BaseType -eq "DocumentLibrary") condition:
    if($list.BaseType -eq "DocumentLibrary")
    $ListURL = $SPWeb.url + "/" + $list.RootFolder.Url
    Write-Output $ListURL
    [Microsoft.SharePoint.SPQuery]$query = New-Object Microsoft.SharePoint.SPQuery
    #$query.Folder = fldr;
    #Recursive Scope....
    $query.ViewAttributes = "Scope='Recursive'"
    $allitems = $list.GetItems($query);
    $filecount = $allitems.Count;
    Write-Output " No of item: " $filecount
    if ($SPWeb -ne $null)
    $SPWeb.Dispose()
    If my contribution helps you, please click Mark As Answer on that post and Vote as Helpful
    Thanks, ShankarSingh

  • Changing the default site collection

    Hi,
    We have two site collections on a dev box. Is there an easy way in central admin or through powershell scripting to change the default site collection?
    thanks,
    Sherazad

    What do you mean by 'Default' site collection?
    If you mean the one that is at the root of a Web Application you would need to move the one there to a new path using Move-SPSite, then move the other one to the root location and (assuming you want a straight swap) move the original root site collection
    to the path previously used by the other one.
    You could backup and restore the sites but that's a bit more effort and confusing imo.
    http://technet.microsoft.com/en-us/library/ff607915(v=office.15).aspx

  • How to disable SCA's from adding other SCA's to the site collection ?

    Hi,
    I have created a web application and under it many site collections. Now I want to disable the feature for any SCA to be able to add any user as SCA's to the site collections. 
    How can i do it? 
    Thank you.

    The only thing I could think of doing would be to create a PowerShell script that checks for the site collection admins you want, and then remove all others. Run this script via Task Scheduler on a regular basis.
    Trevor Seward
    Follow or contact me at...
    This post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.

  • Set multiple Secondary Owners into a site collection

    Hi;
    I try to set multiple Secondary Owners into a site collection but I have execute my script I have only the last Owner (tutu) ?
    My code is :
    $AdminSecondaireArray = ("DC\toto", "DC\titi", "DC\tata", "DC\tutu")
    foreach ($adminsec in $AdminSecondaireArray)
          Set-SPSite -Identity  $SiteCollectionUrl -SecondaryOwnerAlias $adminsec
    Any idea ?
    Regards

    Hi,
    As a workaround, we can add multiple user into a group, then set the group as secondary owner of a Site Collection.
    Set-SPSite -Identity $SiteCollectionUrl -SecondaryOwnerAlias "DC\group"
    Best Regards
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • How to set security group as primary site collection admin and secondary site collection admin using powershell in sharepoint online site - office 365?

    How to set security group as primary site collection admin and secondary site collection admin using powershell in sharepoint online site - office 365?

    Hi,
    According to your description, my understanding is that you want to set security group as admin of primary and secondary site collection using PowerShell command in office 365.
    I suggest you can use the command below to set the group to site owner, then it will have the site collection admin permission.
    Set-SPOSite -Identity https://contoso.sharepoint.com/sites/site1 -Owner [email protected] -NoWait
    Here are some detailed articles for your reference:
    https://technet.microsoft.com/en-us/library/fp161394(v=office.15)
    http://blogs.realdolmen.com/experts/2013/08/16/managing-sharepoint-online-with-powershell/
    Thanks
    Best Regards
    Jerry Guo
    TechNet Community Support

  • How to fetch Properties of all Survey Lists from site collection using Java Script in SharePoint 2013

    Hi,
    I am trying to fetch properties of all lists of "Survey Type" from my site collection in SharePoint 2013 using script editor web part. I am able to fetch properties of one list by mentioning its name explicitly in code but not all survey
    list.
    My task is to display Survey name , description ,Time created and URLs of all survey lists using java script in script editor web part.
    And let me know , if there is any other OOB feature of SharePoint 2013 to achieve the same. 
    Here is the code  :
    <script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    SP.SOD.executeFunc('sp.js', 'SP.ClientContext', sharePointReady);
    function sharePointReady() {
         GetSurveyList();
     function GetSurveyList() {
            var spListTitle = " List Name";
             var clientContext = new SP.ClientContext.get_current();
            var oWeb = clientContext.get_web();
            this.surveyList = oWeb.get_lists().getByTitle(spListTitle);
            clientContext.load(surveyList);
            clientContext.executeQueryAsync(Function.createDelegate(this, this.GetListProperties),Function.createDelegate(this, this.onFailure));
     function GetListProperties() {
            $("#SurveyList").text("");
            var surveyTable = "<table border=1>";
            surveyTable = surveyTable.concat("<tr><td>Survey Name</td>");
            surveyTable = surveyTable.concat("<td>Survey Description</td>");
            surveyTable = surveyTable.concat("<td>Time Created</td>");
            surveyTable = surveyTable.concat("<tr><td>" + surveyList.get_title() + "</td>");
            surveyTable = surveyTable.concat("<td>" + surveyList.get_description() + "</td>");
            surveyTable = surveyTable.concat("<td>" + surveyList.get_created().format("MM/dd/yyyy hh:mm tt")+ "</td>");
                 surveyTable = surveyTable.concat("</table>");
            $("#SurveyList").append(surveyTable);
        function onFailure(sender, args) {
            alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    </script>
    <div id="SurveyList"></div>

    Shifa,
    Please use search result webpart or content query webpart to list all survey list.
    Please 'propose as answer' if it helped you, also 'vote helpful' if you like this reply.

  • Powershell script for removing some users from a particular Site Collection

    Hi,
    I am looking for a PowerShell script to delete a few users from a particular Site Collection. I am unable to delete them from/_catalogs/Users/simple.aspx page therefore need some other medium to
    delete users from the site collection.
    My ultimate aim is to have no user profile with "tp_deleted" field's value as 0 in the USERINFO table. Currently there are about 40 odd users with this field's value as 0 and this is affecting my crawling of this content database.

    Thanks for the reply Alex & eHaze,
    I have a content source of root site which crawls all the site collections under it. Out of the 9 site collections, only 8 are getting crawled and 1 doesn't get crawled at all. The error in the crawl logs is 
    The SharePoint item being crawled returned an error when requesting data from the web service. ( Error from SharePoint site: Value does not fall within the expected range. )
    I tried a lot of things, searched over the net and finally found
    this which helped me solve the same issue in my development environment. I deleted these users from userInfo table and ran a full crawl. And the issue was fixed.
    Now since I cannot delete the users from userInfo table directly from PROD environment, I used .../_catalogs/Users/simple.aspx list
    to delete users from this site collection. While some of the users I could delete, quite a few I could not. Clicking on the profile redirected me to the home page rather than the info page of the profile. 
    This
    is why I have to delete these users from the site collection.
    Alex - the link you shared, I guess it is for a web application level.
    eHaze - the script you shared throws this error:
    Get-SPSite : Cannot find an SPSite object with Id or Url: http://dev-apps/divisions/BT. At C:\PowerShell Scripts\DeleteUserFromSiteCollection1.ps1:4 char:19
    + $site = get-spsite <<<< $siteURL
    + CategoryInfo : InvalidData: (Microsoft.Share...SPCmdletGetSite:
    SPCmdletGetSite) [Get-SPSite], SPCmdletPipeBindException
    + FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletGetSite
    You cannot call a method on a null-valued expression.
    At C:\PowerShell Scripts\DeleteUserFromSiteCollection1.ps1:9 char:27
    + $site.SiteUsers.Remove <<<< ($LoginName)
    + CategoryInfo : InvalidOperation: (Remove:String) [], RuntimeExc
    eption
    + FullyQualifiedErrorId : InvokeMethodOnNull
    hope this info helps.

  • Powershell script to get Site Collection. Site Owner, Title

    Hi,
    I am new to SharePoint, currently I have given one task to create the powershell script which contains the below fields from our two farms. Could you please help me out with the same.
    The script to list out below items:
    Site Collections:
    Site Collection Name:
    Site Collection Owners:
    Last Activity and the size of site collections.
    Many Thanks & Best Regards,
    Naren

    To get all Site Collections:
    If all you want is a list of all site collections in the farm, all you have to do is open a PowerShell window, load the SharePoint Snapin, if you haven't (Add-PSSnapin
    Microsoft.SharePoint.PowerShell), and type Get-SPSite.
    If you want to return the list of site collections for a specific web application, the easiest way is to just pipe it as Get-SPWebApplication
    http://intranet | Get-SPSite
    To get Site Collection Owners:
    Add-PSSnapin "Microsoft.SharePoint.Powershell" -ErrorAction SilentlyContinue
    Get-SPWebApplication "http://mySharePointSite.com"|
    Get-SPSite| foreach-object{ Write-host$_.Url - $_.Owner.Email}
    To get Size of all Site Collections:
    Get-SPSite | select url, @{label"Size in MB";Expression={$_.usage.storage/1MB}} | Sort-Object
    -Descending -Property "Size in MB" | ConvertTo-Html -title "Site Collections sort by size" | Set-Content sc.html
    Regrading the retrieving the last activity I am not sure to what exactly you are looking for but I assume you are concern about getting users last logon time and date using PowerShell.
    For this refer here: Get Users Last Logon Time and Date using PowerShell
    Please remember to upvote if it helps you or
    click 'Mark as Answer' if the reply answers your query.

  • Powershell script to get Audit log settings for all site collections.

    Hi all,
    I am facing issue to get audit log details for all site collection across the farm with the below script. Could someone help me change the script.
    Function AuditValue($url)
    $site=Get-SPSite $url
    auditMask = $site.audit.auditflag
    return auditMask
    Get-SPSite -Limit All | Get-SPWeb -Limit All |
    Select Title,Url,AuditValue(Url)| export-csv "D:\scripts\Test\AuditDetails.csv" -notypeinformagettion
    Thanks Basva

    What errors are you getting? That is if any.
    Scrap that I see a few.
    Not had time to fix it fully. As I am now done at work, but this will help you on your way. It gets back only the audit flag value at the moment.
    Function AuditValue
    $site = Get-SPWeb "http://server" -limit ALL
    foreach($i in $site)
    $auditMask = $site.audit
    $list = $auditMask
    $list | Select-object auditflags
    AuditValue | out-file "C:\temp\AuditDetails.csv"
    EDIT::
    Function AuditValue
    $site = Get-SPWeb "http://SERVER" -limit ALL
    foreach($i in $site)
    $auditMask = $site.audit
    $list = $auditMask
    $list | Select-object @{Name="URL"; Expression ={$site.url}}, auditflags
    AuditValue | out-file "C:\temp\AuditDetails.csv"
    The above will also put URL 
    If this is helpful please mark it so. Also if this solved your problem mark as answer.

  • Sharepoint Online Can not edit anything in Sharepoint designer as Site collection administrator

    Dear all,
    I am using sharepoint online and sharepoint designer 2013. Things were working fine but one day it suddenly stopped working. I have assigned site collection administrator to several accounts and I tried on different computers. I can not edit anything in
    sharepoint designer 2013. Can not edit workflows, can not edit lists. Everything seems to be bugging out. I have reinstalled sharepoint designer and tried on different computers, all of them behave the same. I checked on all accounts I assigned site collection
    admin to, they all have full control over everything. I can edit lists on the sharepoint site with no problem. Anyone knows what's going on?
    I also created another blank site, same thing happens.
    -Timothy

    Are you able to edit site in IE?
    Try below:
    http://blogs.technet.com/b/namkh/archive/2013/04/18/quot-the-web-site-has-been-configured-to-disallow-editing-with-sharepoint-designer-quot.aspx
     One straight forward way of doing it is from the UI (Which did not work in my case though :(  )
      1.  Right-click the ONET.XML file ( at \Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\SiteTemplates\<var><Service></var>\xml) for the site definition and open it with Notepad
           If you see “DisableWebDesignFeatures=wdfopensite” section in the one.xml that means your site has been configured to disallow SharePoint designer.
          You can remove this section from the file and should be able to access the site in designer now
    2.   If you are unable to get rid of “DisableWebDesignFeatures=wdfopensite” or find the correct onet.xml corresponding to your site definition, here is a simple script I put together to see if Designer is disabled on the site using the property
    vti_disablewebdesignfeatures2 and update it as required.
    Manage Permissions and Control Access to Sharepoint Designer
    http://support.microsoft.com/kb/2592376
    If this helped you resolve your issue, please mark it Answered

  • Granting permissions to manage my sites site collections and user profiles

    We currently have no governance in place to deal with user profiles and my site site collections.
    So the farm has quite a large number of both profiles and site collections which are orphaned. We do not currently run the timer job that deletes my site site
    I have a few questions about handling this kind of thing.
    1. We have administrative staff who handle the "off boarding" process. They send out mail to people asking whether project folders continue to be needed, etc. and give project members a month to make copies of the important info. Right now, there
    are a few of these staff which have site collection admin rights on normal projects.
    Is there a way that a powershell script could be constructed to give them the ability to delete obsolete user profiles and site collections without giving them full farm admin rights?
    2. Is there a way to set up an AD or SharePoint group and then use that group as a secondary site collection admin on the my site site collections?
    3. With appropriate permissions, would they be able to grant someone else permission to look at data in the my site collection to determine whether any of it needed to be kept?
    I have been requested as a sharepoint admin to work with the offboarding process staff so that they include the sharepoint my site data in the data that they recommend people check before deleting the data.
    I would like to automate as much of the dealings they have to have with the system as possible, just to reduce unrelated accidental actions.

    1. We have administrative staff who handle the "off boarding" process. They send out mail to people asking whether project folders continue to be needed, etc. and give project members a month to make copies of the important info. Right now, there
    are a few of these staff which have site collection admin rights on normal projects.
    Is there a way that a powershell script could be constructed to give them the ability to delete obsolete user profiles and site collections without giving them full farm admin rights?
    Inder : 
    http://blogs.msdn.com/b/kaevans/archive/2012/06/25/top-recommendations-for-managing-the-my-site-cleanup-timer-job.aspx
    http://www.harbar.net/archive/2011/02/10/account-deletion-and-sharepoint-2010-user-profile-synchronization.aspx
    http://blogs.technet.com/b/seanearp/archive/2009/03/04/sharepoint-profile-cleanup.aspx
    2. Is there a way to set up an AD or SharePoint group and then use that group as a secondary site collection admin on the my site site collections?
    Inder: NO, it has to be a user. But you can go to site action > site settings > site collection administrator > Add that group here.
    3. With appropriate permissions, would they be able to grant someone else permission to look at data in the my site collection to determine whether any of it needed to be kept?
    Inder:  Yes
    If this helped you resolve your issue, please mark it Answered

  • Unable to apply a new site template to a new site collection's root web

    Hi folks,
    Using PowerShell I need to create a new site collection and add a new site template to its root web.  I've tried but failed...
    I created the site template from a team site that I modified and then saved it as a site template and saved the template to an WSP file (in the solutions gallery).
    I have tried both of the following methods but can't find the template to add to the root web of the site collection.  Help!!
    Method 1 - Create the site collection, deploy & install the template as a user solution, and apply the template
    I did the following, but it doesn't work because Get-SPWeb doesn't find it.  If I run Get-SPWeb with no parameters the list it returns doesn't include my template.  So site.GetWebTemplates includes it but Get-SPWebTemplate doesn't.
    # Create the site collection
    $site = New-SPSite $siteURL -OwnerAlias $owner -SecondaryOwnerAlias $secondOwner -name $studentName -Description $description
    # Deploy and install the template
    $wsp = Add-SPUserSolution -LiteralPath $wspPath -Site $siteURL
    $wsp = Install-SPUserSolution -Identity $wspIdentity -Site $siteURL
    # Assign the template.
    $loc= [System.Int32]::Parse(1033)
    $templates= $site.GetWebTemplates($loc)
    foreach ($child in $templates)
    Write-Host $child.Name
    If ($child.Name.EndsWith("ABC")
    # the name of the template that I added ends in "ABC" - when this script runs I the name of my
    #added template displays as "{longGUID}#1ABC"
    $template = $child
    $templateID = $child.Name
    $template = Get-SPWebTemplate $templateID
    # regardless of whether I assign $template above or here the Set-SP_Web assignment below fails
    $web = Get-SPWeb $siteURL
    $web | Set-SPWeb 
    -Template $template
    Method 2 - Deploy and install the template as a farm solution, create the site collection, and apply the template
    I did the following.  After I did the first section (deploy and install the solution to the farm) I was able to go to "Manage Farm Solutions" in CA and it was listed there, but neither
    site.GetWebTemplates nor Get-SPWebTemplate included the site template in their list of templates.
    # Deploy and install the solution to the farm
    $template = Add-SPSolution -LiteralPath "C:\SharePoint\Student Site.wsp"
    $template | Install-SPSolution
    Do {Start-Sleep 2 } while (!((Get-SPSolution $template).Deployed))
    # Create the site collection
    $site = New-SPSite $siteURL -OwnerAlias $owner -SecondaryOwnerAlias $secondOwner -name $studentName -Description $description
    # Assign the template.
    $loc= [System.Int32]::Parse(1033)
    $templates= $site.GetWebTemplates($loc)
    foreach ($child in $templates)
            Write-Host $child.Name
            If ($child.Name.EndsWith("ABC")
    # the name of the template that I added ends in "ABC" - when this script runs I the name of my
    #added template displays as "{longGUID}#1ABC"
                            $template = $child
                            $templateID = $child.Name
    $template = Get-SPWebTemplate $templateID
    # regardless of whether I assign $template above or here the Set-SP_Web assignment below fails
    $web = Get-SPWeb $siteURL
    $web | Set-SPWeb
    -Template $template
    David

    Out of curiosity, are you able to create a site within a site collection using this template? That is, can you create a site that is not the root site (e.g. http://sharepoint/sitecollection/Web)?
    Jason Warren
    Infrastructure Specialist
    Habanero Consulting Group
    habaneroconsulting.com/blog

  • Create a site collection with dedicated content db with the help of server object model

    Hi,
     I have a requirement to implement a create a new site collection with dedicated content db. i have got 2 PowerShell scripts which does the same. first i will  create a content  db and then create the sitecollection with contentdb
    parameter with the created contentdb name.
    Now the site collection created must contain few doc libs and few splists with look up columns, people picker data type, multiline of text, single line of text,choice field. hence i am thinking the below approach:
     1) create a web template and include sp doclibs, splists , site columns in this.
     2) i am thinking of a ui design to create the below:
     These are called "projects" which is actually the site collection with the doclibs, splists and must be created by sharepoint admin on click of a link in my landing page.end users access these "projects"  aka 
    "site collections" and uploads the documents into these projects and collaborate.
    so my question is :  On click of a button can I create a site collection with a dedicated content db based on the web template created with the  hel of  server  object model?
    The other approach is on click of this button call the power shell script which accepts the sitecollection name and contentdb name as parameter. is this possible in  server obj.model ?
    passing a paramter from code behind- visual web part ui to power shell ?
    and it should create the site collec based on the web template and create the content db.
    my doubt #3 : will it not throw error "request timed out" when creating the site collec and contentdb from ui ?

    Try below:
    http://sharepoint.stackexchange.com/questions/21606/programmatically-create-a-site-collection-in-an-existing-mounted-content-databa
    PowerShell is just a wrapper for the object model. You shouldn't need to reference PowerShell in your feature, just create the new site collection with C# inside your feature. There's a blog post here that illustrates some code that may get you started.
    http://blog.mastykarz.nl/programmatically-creating-sites-site-collections-custom-web-template/
    http://blogs.msdn.com/b/vesku/archive/2014/06/09/provisioning-site-collections-using-sp-app-model-in-on-premises-with-just-csom.aspx
    # Enable the remote site collection creation for on-prem in web application level
    # If this is not done, unknon object exception is raised by the CSOM code
    $WebApplicationUrl = http://dev.contoso.com
    $snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
    if ($snapin -eq $null)
    Write-Host "Loading SharePoint Powershell Snapin"
    Add-PSSnapin "Microsoft.SharePoint.Powershell"
    $webapp=Get-SPWebApplication $WebApplicationUrl
    $newProxyLibrary = New-Object "Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary"
    $newProxyLibrary.AssemblyName = "Microsoft.Online.SharePoint.Dedicated.TenantAdmin.ServerStub, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
    $newProxyLibrary.SupportAppAuthentication = $true
    $webapp.ClientCallableSettings.ProxyLibraries.Add($newProxyLibrary)
    $webapp.Update()
    Write-Host "Successfully added TenantAdmin ServerStub to ClientCallableProxyLibrary."
    # Reset the memory of the web application
    Write-Host "IISReset..."
    Restart-Service W3SVC,WAS -force
    Write-Host "IISReset complete."
    If this helped you resolve your issue, please mark it Answered

  • Applying theme to all sites in a site collection SharePoint Foundation 2010

    I am working in SharePoint Foundation 2010 and want to apply a theme found in my top level site to all the remaining sites in the site collection.  I found the following bit of code on-line and put it in a script:
    function Apply-SPTheme([string]$SiteUrl, [string]$webName, [string]$themeName)
     $site = new-object Microsoft.SharePoint.SPSite($SiteUrl)
     $web = $Site.OpenWeb($webName)
     $theme = [Microsoft.SharePoint.Utilities.ThmxTheme]::Open($site,"_catatlogs/theme/" + $themeName + ".thmx")
     $theme.ApplyTo($web,$false)
     $web.Update()
     $web.Dispose()
     $site.Dispose()
    Apply-SPTheme "https://sitename" "" "themeName"
    I call the function in the last line and the web site where I obtained the code indicated that this would put the theme in all other sites.  When I run the script I get the follwing message:
    You cannot call a method on a null-valued expression. At C:\applyTheme.ps1(the script file):6 char:16
    $theme.ApplyTo <<<< <$web,$false>
    +CategoryInfo: InvalidOperation: (ApplyTo:String) [], RuntimeException
    +FullyQualifiedErrorId:InvokeMethodOnNull
    I'm a novice programmer and particularly novice on Powershell. I'm not sure I understand what the problem is or how to fix it.
    I'd appreciate any help.

    I highly recommend going back to the SharePoint 2010 site and going through all of the fundamentals.  If yo allocate an hour a day you should be caught up in two weeks.  This will save you hundreds of hours of fishing for solutions.
    SharePoint is far too complex to be "guessed" at.  You will never guess at its structure. Going through the basics from the ground up will burn the structure of its design into you head.  You will then be able to find answers quickly because you
    will know the documentation and how to ask the questions.
    If you are only a basic Admin then your company should allow the vendor to either do the configurations or pay for you to be trained or compensate you to use your personal time for training.  It would be a win for them.
    There are many very good books on SharePoint and PowerShell.  They are only good if you already have the basics of both.  One that I acquired recently is quite good at you level of involvement as it is a cookbook of solutions in PowerShell for
    normal configuration and administration items that goes beyond what is available on the web site or in the basic training.
    http://www.wrox.com/WileyCDA/WroxTitle/productCd-0470533331.html
    I actually have the 2013 version but you should stick to the 2010 version until you are up to speed.  I bought 2013 as a catch up.  Read it over two long dinners of
    Sushi and Sake.
    The books run the gamut of SP from planning to admin.  They are not technical manuals and not developer books.  They are written for general administration,  You will read through quickly and then refer back to chapters as needed.  As
    your SP site evolves the book will help you evolve with it.
    Start by becoming extremely familiar with all of the resources on the SharePoint 2010 product site.  Post future requests that are SharePoint related to the SP forums.  They are very good with PowerShell at this time (three versions but they seem
    to have caught up) - They know the product better than most here and are closer to the MS MVPs on SharePoint.  If there is a pure PowerShell issue then the people in this forum can very helpful,
    Here are all of the SharePoint forums:
    http://social.msdn.microsoft.com/Forums/sharepoint/en-US/home?filter=alltypes&sort=lastpostdesc&brandIgnore=true
    ¯\_(ツ)_/¯

Maybe you are looking for

  • Ref. PO no. is not coming in second line item at the time of delivery

    Hi All STO Scenario In PO it single Line item,  but in delivery we doing split batch. the system showing error that " Enter the    PO No." But in first line it it picking the Ref. Document No. while it not coming second line item. Please suggest. Reg

  • Saving FCP files error

    I've never come across this more than upsetting error message before but was curious if anyone else had. I am basically getting an error message that says Error: Unknown File whenever I try to save my project. I've tried changing the name of the file

  • Playing Albums Sequentially on iPhone 5 (IOS7.0.x)

    Hi, There were 24 pages on one post on a similar, but not quite the same subject.  You'd think that someone in that faceless, nanny knows best, ivory tower would have taken some notice by now.  But anyway, I thought I stood more chance of getting a r

  • Installation of JDK 1.2 on Pentium 4 machine

    I can not seem to install JDK 1.2 on Pentium 4. I have taken care of PATH and CLASSPATH in Autoexec.bat.I have also tried installing it on two different systems. I am able to install a higher version of the same but I need JDK 1.2 only. Can somebody

  • WRT54G Ver 2.0 - No firmware download available

    Hi all, I was able to find all versions of firmware for my router's model number (WRT54G Ver 1.0 to 8.2), except for Ver. 2.0, which I have. Any advice welcome.