Powershell Script to create "custom" Document Library

I have a powershell script which creates a Document Library for every user in AD.
This works, but rather than using the default Document Library I want it use a custom Document Library.  However this isnt working.
My script to create the default Document Library is this...
[System.Reflection.Assembly]::Load("Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c")
$site = new-object Microsoft.SharePoint.SPSite("http://servername/sitename");
$siteweb = $site.OpenWeb();
$webs = $siteweb.Webs;
$strFilter = "(&(objectCategory=User)(name=accountname))"
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.PageSize = 1000
$objSearcher.Filter = $strFilter
$objSearcher.SearchScope = "Subtree"
$colProplist = "samaccountname"
foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}
$colResults = $objSearcher.FindAll()
foreach ($objResult in $colResults)
$objItem = $objResult.Properties; $objItem.samaccountname
$listTemplate = [Microsoft.SharePoint.SPListTemplateType]::DocumentLibrary
$listId = $siteweb.Lists.Add($objItem.samaccountname, "", $listtemplate);
$list = $siteweb.Lists.GetList($listId, $true);
$roleDef = $siteweb.RoleDefinitions.GetByType("Contributor");
$user = "domain\" + $objItem.samaccountname;
$rolAssign = new-object Microsoft.SharePoint.SPRoleAssignment($user, "email", "name", "notes");
$rolAssign.RoleDefinitionBindings.Add($roleDef);
if(!$list.HasUniqueRoleAssignments)
{$list.BreakRoleInheritance($true);}
for ($i = $list.roleAssignments.Count - 1; $i -gt -1; $i--)
{ $list.RoleAssignments.Remove($i) }
$list.RoleAssignments.Add($rolAssign);
$list.Update();
Now I have a custom Document Library named "TESTLIB" so if I substitute the line:
$listTemplate = [Microsoft.SharePoint.SPListTemplateType]::DocumentLibrary
with
$listTemplate = [Microsoft.SharePoint.SPListTemplateType]::TESTLIB
Then it errors with this...
How can I script powershell to create a "custom" Document Library?
Thanks

The below link should help you in creating custom document library using powershell
http://blogs.technet.com/b/heyscriptingguy/archive/2010/09/23/use-powershell-cmdlets-to-manage-sharepoint-document-libraries.aspx
Vinod H
Thanks for the link but I cant see anything to assist creating a custom library?  Was there something in paticular you saw?

Similar Messages

  • Save output of powershell script to a SharePoint document library?

    Hi
    I've got the PS script below which scripts out our SQL replication so disaster recovery.  Is there a way to output this to a SharePoint document library so that way we can version control the file to keep multiple copies and it also avoids outputting
    this to a file share.  We would still need to have the files with the .sql extension format which is an allowed file type in our farm.
    Thanks
    #Load command-line parameters - if they exist
    param ([string]$sqlserver, [string]$filename)
    #Reference RMO Assembly
    [reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Replication") | out-null
    [reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Rmo") | out-null
    function errorhandler([string]$errormsg)
        writetofile ("-- Replication Script Generator run at: " + (date)) $filename 1
        writetofile ("-- [Replication Script ERROR] " + $errormsg) $filename 0
    function writetofile([string]$text, [string]$myfilename, [int]$cr_prefix)
        if ($cr_prefix -eq 1) { "" >> $myfilename }
        $text >> $myfilename
    function initializefile([string]$myfilename)
        "" > $myfilename
    trap {errorhandler($_); Break}
    #Deal with absent parameters
    [string] $hostname=hostname
    if ($sqlserver -eq "") {$sqlserver = read-host -prompt "Please enter the server name or leave blank for Hostname"}
    #if ($filename -eq "")  {$filename = read-host -prompt "Please enter the file name (eg 'c:\ReplicationBackupScript.sql')..."}
    if ($sqlserver -eq "")   {$sqlserver = $hostname}
    if ($filename -eq "")   {$filename = "d:\Rep\CreateReplication-$(get-date -format ddMMyyyy).sql"}
    # Clear file contents
    if (Test-Path  ($filename)) {Clear-Content $filename}
    $repsvr=New-Object "Microsoft.SqlServer.Replication.ReplicationServer" $sqlserver
    initializefile $filename
    # if we don't have any replicated databases then there's no point in carrying on
    if ($repsvr.ReplicationDatabases.Count -eq 0)
        writetofile ("-- Replication Script Generator run at: " + (date)) $filename 0
        writetofile "-- ZERO replicated databases on $sqlserver!!!" $filename 1
        EXIT
    # similarly, if we don't have any publications then there's no point in carrying on
    [int] $Count_Tran_Pub = 0
    [int] $Count_Merge_Pub = 0
    foreach($replicateddatabase in $repsvr.ReplicationDatabases)
            $Count_Tran_Pub = $Count_Tran_Pub + $replicateddatabase.TransPublications.Count
            $Count_Merge_Pub = $Count_Merge_Pub + $replicateddatabase.MergePublications.Count
    if (($Count_Tran_Pub + $Count_Merge_Pub) -eq 0)
        writetofile ("-- Replication Script Generator run at: " + (date)) $filename 0
        writetofile "-- ZERO Publications on $sqlserver!!!" $filename 1
        EXIT
    # if we got this far we know that there are some publications so we'll script them out
    # the $scriptargs controls exactly what the script contains
    # for a full list of the $scriptargs see the end of this script
    $scriptargs = [Microsoft.SqlServer.Replication.scriptoptions]::Creation `
    -bor  [Microsoft.SqlServer.Replication.scriptoptions]::IncludeEnableReplicationDB `
    -bor  [Microsoft.SqlServer.Replication.scriptoptions]::IncludeCreateLogreaderAgent `
    -bor  [Microsoft.SqlServer.Replication.scriptoptions]::IncludePublicationAccesses `
    -bor  [Microsoft.SqlServer.Replication.scriptoptions]::IncludeArticles `
    -bor  [Microsoft.SqlServer.Replication.scriptoptions]::IncludePublisherSideSubscriptions `
    -bor  [Microsoft.SqlServer.Replication.scriptoptions]::IncludeSubscriberSideSubscriptions
    writetofile ("-- Replication Script Generator run at: " + (date)) $filename 0
    writetofile "-- PUBLICATIONS ON $sqlserver" $filename 1
    writetofile "-- TRANSACTIONAL PUBLICATIONS ($Count_Tran_Pub)" $filename 1
    foreach($replicateddatabase in $repsvr.ReplicationDatabases)
        if ($replicateddatabase.TransPublications.Count -gt 0)
            foreach($tranpub in $replicateddatabase.TransPublications)
                writetofile "/********************************************************************************" $filename 0
                writetofile ("***** Writing to file script for publication: " + $tranpub.Name) $filename 0
                writetofile "********************************************************************************/" $filename 0
                [string] $myscript=$tranpub.script($scriptargs) 
                writetofile $myscript $filename 0
    writetofile "-- MERGE PUBLICATIONS ($Count_Merge_Pub)" $filename 1
    foreach($replicateddatabase in $repsvr.ReplicationDatabases)
        if ($replicateddatabase.MergePublications.Count -gt 0)
            foreach($mergepub in $replicateddatabase.MergePublications)
                writetofile "/********************************************************************************" $filename 0
                writetofile ("***** Writing to file script for publication: " + $mergepub.Name) $filename 0
                writetofile "********************************************************************************/" $filename 0
                [string] $myscript=$mergepub.script($scriptargs) 
                writetofile $myscript $filename 0

    Check out Using PowerShell to upload a scripts output to SharePoint
    Jason Warren
    @jaspnwarren
    jasonwarren.ca
    habaneroconsulting.com/Insights

  • How to create a document library in Sharepoint Online using Powerpoint?

    I've been trying to create a document library in Sharepoint Online via pwoershell and I've been trying to see if anyone else has the code but the only scripts i could find are for Sharepoint 2010 on-premise and it's not compatible with Sharepoint 2013.
     Can anyone help me?
    Thanks!
    Dearbhla Bradley

    It's SharePoint Client-side Object Model.  Here are few references:
    http://msdn.microsoft.com/en-us/library/office/jj193041(v=office.15).aspx
    http://msdn.microsoft.com/en-us/library/office/dn268594(v=office.15).aspx
    These postings are provided "AS IS" with no warranties, and confers no rights.

  • Corrupt document gets created in document library with document template using createlistitem workflowaction in visual studio workflow for office 365 solution

    Hi,
    My requirement is to create a document library associated to a custom content type with a document template associated. Also I need to create a document based on the template in this document library when a new item is created in another list by taking the
    reference ID of that new Item , I need to create the document with the name appended by ID. I need to do all this deployment using WSP.
    I have created document library with document template associated to content type by following instructions in below stated blog :http://blogs.msdn.com/b/chaks/archive/2011/05/19/deploying-a-document-template-file-in-content-type-in-a-office365-sandboxed-solution.aspx
    This works perfect for me.
    However, there are few observations, when going to Document Library > Library Settings > Advanced Settings > Document Template section - doesnt shows the Edit template link. When tried to look at the value for the document template using view source
    , it is giving me /Lists/MyDocsListInstance/Forms/template.dotx instead of the actual template file uploaded.
    Ignoring the above observation, when I am trying to create a sandbox based workflow in visual studio to create document in document library when new item is created in another list, I provide the ContentTypeID as the ID associated with the document library
    with template. 
    It creates the corrupt document at end of workflow. 
    I have tried using .docx instead of .dotx files for workflow as per solution provided in some of the post but it isnt resolving my issue.
    Any help is much appreciated.
    Regards,
    Krutika

    OK, I am going to throw out a lot of ideas here so hopefully they get you closer to a diagnosis. Hang on :)
    Does it happen to work for some users but not others? If so, try logging in on the "good" computer with the "bad" username. This will tell you if the problem is related to the end-user's system. Also, once the user downloads a document
    successfully can they open and work on it in Word? Also, does the document library have any custom content types associated with it or does it just use 'Document'?
    I notice that there are other folks on the web that have run into this same problem and the similarity seems to be that they are either on SharePoint 2007 or have upgraded from 2007. Did this doc library start out as a 2007 library?
    What you might want to do is this: Make a site collection from scratch in 2013 (or find one that you know was created in 2013). Choose team site (or whatever you want) for the root web and set up the security the same way you have it on the malfunctioning
    library. Now, use windows explorer to copy and paste some of the documents to the new location. Be sure you recreate any needed content types. Now test it from the troubled user's computer.
    I'm thinking there may be something that is different about the library since it was migrated through various versions and updates since 2007. I've sometimes found that there can be problems (especially with user profiles but that's a different story) with
    things that go through this evolution.

  • PowerShell script to list ALL documents bigger than 10MB - in list attachments/libraries all over my site?

    Hi there,
    Just wondering if someone can give me the PowerShell script to list ALL documents bigger than 10MB - in list attachments/libraries all over my site?
    Really appreciated.
    Thank you.

    Hello,
    here you can find sample to help you create yoru script :
    http://sharepointpromag.com/sharepoint/windows-powershell-scripts-sharepoint-info-files-pagesweb-parts
    see this sample extract from this site
    Get-SPWeb http://sharepoint/sites/training |
                                     Select -ExpandProperty Lists |
                                     Where { $_.GetType().Name -eq "SPDocumentLibrary" -and
                                             -not $_.Hidden }
    |
                                     Select -ExpandProperty Items |
                                     Where { $_.File.Length -gt 5000 } |
                                     Select Name, {$_.File.Length},
                                            @{Name="URL";
                                            Expression={$_.ParentList.ParentWeb.Url
    + "/" + $_.Url}}
    this can help too :
    https://gallery.technet.microsoft.com/office/Get-detail-report-of-all-b29ea8e2
    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?

  • Custom document library showing wrong file type icon

    Hi All - I have a custom document library created using VS code. In search result if any document appear from that library it shows web page icon.
    I found this below url for this issue:
    http://www.neilrichards.net/sharepoint/missing-document-icons-from-search-results-with-fast-for-sharepoint/comment-page-1#comment-1043
    I don't want to write custom pipe line and I also don't want to hard code file types in XSLT. 
    Is there any solution to change content class?
    There is difference in contentclass in source XML.
    for 
    <imageurl imageurldescription="Image">/_layouts/images/imageresult_16x16.png</imageurl>
    <contentclass>STS_ListItem_DocumentLibrary</contentclass>
     icon is displayed correctly.
    for
     <imageurl imageurldescription="List Item">/_layouts/images/STS_ListItem16.gif</imageurl>
    <contentclass>STS_ListItem_10623</contentclass>
    Icon is displayed wrong.

    yeah its problem with library, But how to fix this?.
    http://www.neilrichards.net/sharepoint/missing-document-icons-from-search-results-with-fast-for-sharepoint/comment-page-1#comment-1043

  • Create custom document with wrong size

    Hi,
    I have a problem (on Sun Solaris 5.8) when I create custom document with more than 10MB size.
    I've created an agent which detects the events on a custom data type
    MYDOCUMENT (extension .mydoc).
    When I put a new document test1.mydoc (size of 10MB for example), my agent detects the new document, creates a copy, sets the class object to
    MYDOCUMENT , removes the original document and puts the copy into the same folder.
    But sometimes, the copy created has a wrong size (less then 10MB).
    How can I configure the nfs server to be sure that the agent waits for the complete size of the added document.
    I need HELP !!!!
    Thanks

    Hi Pavithra,
                    yeah you can create your custom table by entering fields in Standard.  for more details
    refer below screen shots
    Regards,
      Thangam.P

  • Create Dynamic Document Library Templates

    I have the following scenario within our IT Org
    1. PMO office maintains a "Standards" library, to which they publish all standard templates that need to be used for Project Management.
    2. Each Project Manager would like to create a document library within their "project site" based on all the documents within "Standards" library.
    My question is, would it be possible to create a document library template whose contents are dynamically pulled from another library?
    Thanks.

    Hi ,
    Based on your description, my understanding is that each Project Manager
    creates document library with the same template, but what they need is that their document libraries have different content type with others.
    There isn’t an out of the box method to create document library templates dynamically.
    For your issue, I suggest each Project Manager create one document content type with the document template which they need, and add the content type into their document libraries. 
    Here is a similar case, you can use as a reference:
    http://social.technet.microsoft.com/Forums/en-US/7d238bb5-8af7-4027-97cf-b41f84bcdb5d/dynamically-create-document-templates-for-new-menu?forum=sharepointdevelopmentlegacy
    Best Regards, 
    Lisa Chen

  • Need to create interactive document library

    Hello Everyone
    I need to create interactive document library in sharepoint 2013. When user uploads document, he should be able to write comment below that document and other users should be able to reply or post other document as well.
    Is it possible to achieve this kind of feature in sharepoint?
    Thanks

    Hi,
    Have you Configure social computing features in SharePoint Server 2013.
    Enable the "SharePoint Server Standard Site Collection features" 
    https://<< Site URL >>/_layouts/15/ManageFeatures.aspx?Scope=Site
    So that missing Social collaboration features are added into webpart catalog.
    thx
    iffi

  • PowerShell Script to Create a Contact Card and Enable Email Forwarding

    Exchange 2010
    Can anyone help with creating a powershell script to create a contact card and set email forwarding at the sametime?
    I'm looking to import a list of 200 users via a text or csv file, create the contact card with first name, middle initial if one exists, last name, (no alias) and put the contact card in the following OU "DIS###" in the a.b.c.com domain as well
    as enable forwarding to @mail.com.
    I've been able to create a script to enable mail forwarding but it doesn't help me without a contact card.  I hate to put this upon anyone, but my ps scripting and Exchange knowledge is still in it's infant stage and I need get this done post haste

    Q:Import csv: Does this contain 200 mailboxes name
    A:It contains 200 user logon names.
    For the mail forwarding:
    I currently have a csv file with two columns -- one named displayname and the next call mailaddress.  Under the displayname column I have the users account name (first.mi.last -- middle initial if they have one) and under mailaddress i have @mail.com.                                                                                                           
    script:                                                                                                                                                                    
    Import-CSV C:\setmailforwarding\mailforwarding.csv | foreach-Object{Get-Mailbox $_.displayname | set-Mailbox -forwardingAddress $_.mailaddress}
    The above script should work if the contact card has been created.  Obviously I need to create the card first.
    I don't have a script to set up the contact card as of yet -- I was hoping to get some help on that.
    Q:E-mail forwarding: Is this  from  mailboxes to mail contact, you will be creating
    A:Not really sure what you are asking.  I'm looking to create the contact card with a csv or txt file for first name, middle initial if one exists, last name, (no alias) and put the contact card in the following OU "DIS###" in the a.b.c.com domain as
    well as enable forwarding to @mail.com.  The users current email is @mail.1234.com and we will be migrating our mailboxes to another organization that uses @mail.com.  I will need to set forwarding in the interim until the migration is complete.
    Hope this helps.

  • Creating a document library with a custom template

    What I want is basically a good solution for people to be able to fill out a form on the web and then save it in the online library.
    You need to be able to automatically create a document from a template in just one or two clicks from the page and then automatically save it to the online-library.
    When this is done, the admin of the site will get a notification (this i think i know how to fix thought) so he can examine the new document instantly.
    How can this be done?

    That's more or less out of the box behaviour. Create a content type on a list or library depending on what your template is (word doc, InfoPath form, list item with styling etc.), then create an alert for your admin on the list.
    Your users can then create new items and save them in the list/library. The process is simpler with list items or InfoPath forms as they don't give you the wide choice of actions that you get in word docs etc..

  • How to create a document library with the attachments of a task list?

    Hi!
    Basically, I need to create an event handler, that in the time when a file is attached to a task, make a copy of the file in the document library. Unfortunately this requires knowledge in programming and is not even possible for me to install the software
    i need in the company computers to try. Any ideas?      

    Unless you have third party workflow options, custom development IS required.
    There are several options when it comes to the development, some of which do not require admin involvement... but they still require programming.
    Scott Brickey
    MCTS, MCPD, MCITP
    www.sbrickey.com
    Strategic Data Systems - for all your SharePoint needs

  • Unable to delete column created under document library.

    I've created custom column in SharePoint online (2013). I want to delete one column from my document library. In library settings all columns are showing but its not clickable to select and delete the particular column.
    Please advice.

    Hi,
    Thanks for posting your issue, you won't be able to delete the required column like Tittle, Name from the Document library. you can hide this column.
    f the column is on a content type in the library, then first remove it from the content type and then from the library.
    Kindly find the below URL to know about hiding and deletion of columns in Document library
    http://support.microsoft.com/kb/2657619
    http://www.codeproject.com/Articles/28005/To-remove-the-title-column-from-a-Sharepoint-list
    http://mscerts.programming4.us/sharepoint/sharepoint%202010%20%20%20change%20or%20remove%20a%20column%20in%20a%20list%20or%20document%20library.aspx
    I hope this is helpful to you, mark it as Helpful.
    If this works, Please mark it as Answered.
    Regards,
    Dharmendra Singh (MCPD-EA | MCTS)
    Blog : http://sharepoint-community.net/profile/DharmendraSingh

  • Update Symbol and Symbol Script without removing from Document library

    Is there a way in fireworks CS5.1 to update a symbol and the corresponding symbol script without removing it from the document library like it suggests in the below article
    http://www.adobe.com/designcenter/fireworks/articles/frwcs3_richsymbol_print.html

    I have done some more research on this question and there appears to be no way to update a symbol script without removing it from the document library, hopefully this bug will be patched in the near future

  • Delivery Error when creating Sharepoint Document Library subscription

    Recently we have been having issue with a subscription from a report we have.
    We have a report that has been generated and have a subscription from that report to create a PDF document within sharepoint.
    Recently the subscription stopped working and we have these errors showing:
    A delivery error has occurred. ---> Microsoft.ReportingServices.Diagnostics.Utilities.DeliveryErrorException: A delivery error has occurred. ---> Microsoft.ReportingServices.Diagnostics.Utilities.InvalidExtensionParameter: One of the extension parameters
    is not valid for the following reason: Failed to validate the delivery setting PATH.The specified user USERNAME could not be found.
          Failed to validate the delivery setting PATH.The specified user USERNAME could not be found
    Looking into this, I found a few things but they did not help.
    One thing was to install update 5 for SQL server 2012 R2, but that didn't help.
    Another thing was saying something about there being 2 user accounts, a claims account and a windows user account, but I couldn't figure out how to make it use the correct account.
    I also tried to save it to a Windows File Share, and try to save it to the Sharepoint server side, however that failed stating it couldn't find that path.
    Being that sharepoint is tricky with its file store (is there really a location on the server that files are stored, I cant find it) I could not figure it out.
    I know I can windows explorer to the file location, \\site\shared documents\Folder but if I go to the web servers that host sharepoint I can't find where this path really is.
    Thanks

    Hi,
    According to your post, my understanding is that you want to get error in accessing sharepoint document library files.
    The cause is that the account being used to validate accounts on the production domain had been set to expire the password according to the general domain policy.
    Once the account is set to never expire, the issues will disappear.
    For more information, you can refer to:
    http://kb4sp.wordpress.com/2012/12/05/user-cannot-be-found-shenanigans-one-way-active-directory-trusts-and-sharepoint-2013/
    http://blogs.msdn.com/b/cliffgreen/archive/2013/02/19/sharepoint-2013-the-directory-is-not-a-subdirectory-of-the-root-directory.aspx
    Best Regards,
    Linda Li
    Linda Li
    TechNet Community Support

Maybe you are looking for

  • Error Message: "An error occurred while trying to save your photo library."

    I am all of the sudden getting this error message while in iPhoto, seems to come up after I try to delete some photos: "*An error occurred while trying to save your photo library.* Some recent changes may be lost. Make sure your hard disk has enough

  • Chart of depreciation(urgent)

    Dear all, While assigning chart of depreciation to company code, i am getting the following error. Please make me come out of this error. Will assign points. Thanks in advance, Regards, A.Anandarajan. Company code entries for 3600 are incomplete - Se

  • RTMPS in Chrome and Firefox/Linux

    I've been working with the Beginning AS3 Tutorial which streams a video from Flash Media Server. I've been trying to enable RTMPS for this demo and it works correctly in Firefox and IE on Windows (usingTLS == true) but does not work (usingTLS == fals

  • Microsoft Apps in SW update (OTA)

    Hi Nokia Today I checked'up SW update app on my phone and see that there's update named 'Microsoft Apps'. So I wanted to know - what kind apps are they? Will be new Microsoft Office available for Belle users and how soon? 

  • Starting Tomcat using jsvc and jpda

    This is mostly just a message for anyone else looking for an answer to how to start Tomcat as a daemon with webapp remote debugging enabled. There is a real lack of information on how jsvc works when starting Tomcat under *nix.  I'm using Solaris 10,