Add a list and column to about 200 sites using powershell in SharePoint online


I have a sitecollection with about 200 identical sites. However I need to add a new list to each site and a lookup column (referring to this list) to two other lists. I'm not a developer so I struggle a bit. I found this as a starting point:
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime") | Out-Null
$WebUrl = 'https://yourtenant.sharepoint.com/sites/somesite'
$EmailAddress = "[email protected]"
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($WebUrl)
$Credentials = Get-Credential -UserName $EmailAddress -Message "Please enter your Office 365 Password"
$Context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($EmailAddress,$Credentials.Password)
$List = $Context.Web.Lists.GetByTitle("YourList")
$FieldXml = "<Field Type='Text' DisplayName='New_Field_Display_Name' />"
$Option=[Microsoft.SharePoint.Client.AddFieldOptions]::AddFieldToDefaultView
$List.Fields.AddFieldAsXml($fieldxml,$true,$option)
$Context.Load($list)
$Context.ExecuteQuery()
$Context.Dispose()
Can someone help me out or is there a better solution?
Thanks.


Hi,
According to your post, my understanding is that you wanted to add a list and a lookup column in about 200 identical sites.
Per my knowledge, there is no out of the box way to achieve it in SharePoint Server, however, I’m not sure whether it is in SharePoint online.
As this is the forum for SharePoint Server, you can post your question in the forum for SharePoint online.
http://community.office365.com/en-us/forums/154.aspx.
However, as you had known, we can achieve it programmatically.
Besides the PowerShell command, we can also use the Client Object Model to achieve your scenario.
If all the 200 sites in one site collection, we can first retrieve all the sites in the site collection, then add the list in every site.
To retrieve all the sites in a site collection, you can refer to the following code snippets.
static string mainpath = "SiteURL";
static void Main(string[] args)
getSubWebs(mainpath);
Console.Read();
public static void getSubWebs(string path)
try
ClientContext clientContext = new ClientContext( path );
Web oWebsite = clientContext.Web;
clientContext.Load(oWebsite, website => website.Webs, website => website.Title);
clientContext.ExecuteQuery();
foreach (Web orWebsite in oWebsite.Webs)
string newpath = mainpath + orWebsite.ServerRelativeUrl;
getSubWebs(newpath);
Console.WriteLine(newpath + "\n" + orWebsite.Title );
catch (Exception ex)
http://chennaisharepointtraining.blogspot.in/2011/11/get-all-subwebs-using-client-object.html
To create a list, you can have a look at the following article.
http://msdn.microsoft.com/en-us/library/office/fp179912(v=office.15).aspx
Thanks,
Jason
Forum Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
[email protected].
Jason Guo
TechNet Community Support

Similar Messages

  • 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

  • Feature that automatically creates a list and columns

    Hi,
    I wanted to create a feature that automatically creates a list and columns programatically. Can anyone please help me how to implement this.
    Regards,
    Praveen

    Please check below article to create columns and list programatically
    http://www.sharepointdoug.com/2012/12/programmatically-creating-content-type.html
    similar thread below to create list programatically
    https://social.msdn.microsoft.com/Forums/sharepoint/en-US/2d82a8fd-052c-4d24-bfef-3ff59986b29c/how-to-create-custom-list-in-sharepoint-2010-programmatically-?forum=sharepointdevelopmentprevious
    My Blog- http://www.sharepoint-journey.com|
    If a post answers your question, please click Mark As Answer on that post and Vote as Helpful

  • Just upgraded my ipad 2 software to iso7 and all my Video name titles have gone? I have 4 films on the ipad and I share about 200 films from my pc, now to watch a film I need to randomly select one to see which film it is before I play it.. This is bad!

    Just upgraded my ipad 2 software to iso7 and all my Video name titles have gone? I have 4 films on the ipad and I share about 200 films from my pc, now to watch a film I need to randomly select one to see which film it is before I play it.. This can’t be right! Help!!

    You cannot go back to an earlier version of iOS.
    If you are having Wi-Fi problems I suggest going to some location that offered free Wi-Fi. Your library or a Starbucks perhaps. Does your iPad connect there and work well?
    If your iPad works well there you can eliminate the iPad and it's iOS as the cause of your problem.
    If your iPad still acts up when connecting to the other Wi-Fi sources I'd suggest a visit to an Apple store to help discover the problem. Be sure to make an appointment prior to going to the Apple store.

  • As i upgraded my iphone 4 to ios5 i cant edit my phone list  and the i message won't use my phone number, what shall i do

    as i upgraded my iphone 4 to ios5 i cant edit my phone list  and the i message won't use my phone number, what shall i do

    Hi drgpeck,
    This article is for a similar issue, and the troubleshooting steps would be recommended for your specific issue:
    iTunes for Windows: iTunes cannot contact the iPhone, iPad, or iPod software update server
    http://support.apple.com/kb/TS1814
    Cheers!
    - Ari

  • How to rename content type on web site level and underneath all the document libraries using powershell?

    Hello
    I wantto rename content type on web site level and underneath all the document libraries using powershell, please let me know how can do this?
    I saw this url
    http://suryapulipati.blogspot.in/2011/08/rename-content-type-name-in-list-using.html, but I want to change everything from Web Site, subsite and underneath document libraries. Because if you try to change on any on document library, it will be applicable
    for that document library, if you change on web level then underneath document libraries content type names not updated automatically.
    Please advise
    Avi

    Not sure with powershell.
    I could help you out with Server Side or Web Services though.
    Brandon James SharePoint Developer/Administrator

  • In my Itunes page the add play list and all other buttons are missing

    In my Itunes the add play list button and all others at the buttom of the page are not visiable hos anyone else run into this problem?

    Hi kirsty1211,
    If you are having issues downloading your purchases to your laptop, you may find the following articles helpful:
    Apple Support: Downloading past purchases from the App Store, iBookstore, and iTunes Store
    http://support.apple.com/kb/HT2519
    iTunes Store: Troubleshooting iTunes Match
    http://support.apple.com/kb/ts4054
    Regards,
    - Brenden

  • Check flat file column list and column types

    Hi guys!
    Is there any "easy" way to check if the source flat file column names and column types correspond to target datastore column name and types ?
    Regards,
    PsmakR

    Hi,
    There is a way that I already used some time to validate if the data is the one expected into target.
    Conditions:
    1) The file source must have all columns as "String"
    2) All mapping for the analysed columns must be done at "staging area"
    How I do it: (oracle way)
    1) create a database function (by ODI procedure) like:
    create or replace function F$_DATATYPE (pData in varchar2, pDatatype in varchar2, pFormat in varchar2)
    return varchar2 as
    vDate date;
    vNumber number;
    BEGIN
    if pDatatype = 'D' then /* Date */
    vDate := to_date(pData, pFormat);
    elsif pDatatype = 'N' then /* Number */
    if pFormat is null then
    vNumber := to_number(pData);
    else
    vNumber := to_number(pData, pFormat);
    end if;
    end if;
    return 'OK';
    EXCEPTION
    When OTHERS then
    return 'KO';
    end F$_DATATYPE ;
    3) Now you can create a constraint to each source column that you wish to validate data like:
    'OK' = F$_DATATYPE(my_source_column, 'D', 'ddmmyyyy hh24:mi:ss' ) /* to a date column as example */
    4) drag and drop the source datasource (table from model) into package and a E$ table with all errors will be created.
    Does it help you?

  • Add Column to an existing CSV using powershell

    Hi Everyone,
    I am horribly stuck in building a logic of how can i add a column with certain details in an existing CSV using powershell. I tried many things one of the code is posted below.
    The situation is , I have a Folder path ' D:\Exclusion\Final1' it contains a list of CSV's that looks like below:
    preprocessed1.csv
    CI,Environment
    vm-Serv1,Test
    preprocessed2.csv
    CI,Environment
    vm-bkp1,Prod
    and so on with same structure..
    Then I have another CSV that Contains certain list of Patches and Title
    looks like:
    Master_Exclusion.csv
    Title, Patch
    xyz, KB23109
    abc, KB432344
    yyy, KB321221
    What I am Trying to do is to Copy the Column 'Patch' from here and copy them to all the CSVs present at ' D:\Exclusion\Final1'
    and  the output would look like :
    preprocessed1.csv
    CI ,Environment , Patch
    vm-Serv1, Test     ,KB23109
                                KB432344
                                KB321221
    CI,Environment,Patch
    vm-bkp1,Prod,  ,KB23109
                            KB432344
                            KB321221
    $filepathex=Get-ChildItem D:\Exclusion\Final1
    foreach($fileex in $filepathex)
    $exclusion=Import-Csv D:\Exclusion\Master_Exclusion.csv
    $list=Import-Csv D:\Exclusion\Final1\$fileex
    $list |
    Select-Object *,@{Name='Patch';Expression={$exclusion.Patch}}} |
    Export-Csv D:\Exclusion\Split2\$fileex -Append -NoTypeInformation
    Thanks in Advance for any help or suggestions.

    I am extremely sorry for the confusions , actually I am trying to just add a new column named "Patch" to a a list of existing CSV's . the patch column is present in another CSV i need to append it to the list of CSV's
    Like
    existing csv:
    CI,Environment
    vm-serv,Test
    and another CSV is 
    Master_Exclusion.csv
    Title,Patch
    xyz,kb084932
    yrx,KB893748
    trw,kb949298
    The output would be :
    output.csv
    CI,Environment ,Patch
    vm-serv,Test,kb084932
                         KB893748               
                          kb949298

  • How to get the Row and Column values in ALV (without using Objects)

    Hi All,
    I need to get the Row / Column when double click is used in ALV, I can use the double click event for this. However, I do not want to use the Object Oriented ALV. I want to implement the same functionality using general (using functions) ALV.
    Is there any way to get the row / column values for a Generia (non-OOPs) ALV report.
    Please help.
    Thanks,
    Vishal.

    Hello,
    The only think you have to do is to get the index where the user clicked, and then read the internal table you sent to the alv
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program       = 'prg_name'
          i_callback_pf_status_set = 'SET_PF_STATUS'
          i_callback_user_command  = 'USER_COMMAND' " this is to the click event!!
          i_callback_top_of_page   = 'TOP_OF_PAGE'
          is_layout                = alv_layout
          it_fieldcat              = alv_fieldcat
          i_save                   = 'A'
          it_events                = alv_events[]
        TABLES
          t_outtab                 = i_totmez.  ---> TOUR IT.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    " then....
    FORM user_commandUSING r_ucomm     TYPE sy-ucomm
                                    ls_selfield TYPE slis_selfield.
    " r_ucomm -> HAS THE STATUS
    " ls_selfield-tabindex  -> HAS THE SELECTED INDEX
    " THEN READ THE INTERNAL TABLE
    " HERE YOU WILL HAVE THE SELECTED ROW
    READ TABLE i_totmez INDEX ls_selfield-tabindex.
    ENDFORM.
    cheers,
    Gabriel P.

  • I have installed the java plugin but it does not appear in my add-on list. I have RedHat linux OS using the Firefox 24.2.0 browser.

    I have already followed your advice for removing the plugins.dat file from the .mozilla directory. The plugin still hasn't appeared in the add-on list. Does anybody have any idea what could be going on?

    See:
    *http://kb.mozillazine.org/Java
    *http://kb.mozillazine.org/Determining_plugin_directory_on_Linux
    *https://developer.mozilla.org/en/Gecko_Plugin_API_Reference/Plug-in_Basics#How_Gecko_finds_plug-ins

  • Can we add users to the 'Manage Access Request' field to process site access request in SharePoint Online?

    Hi,
    I have a requirement in which I have to assign couple of email ids to the "Manage Access Request" field to process site access requests. And, this is possible using server object model but I have to achieve this on SharePoint Online with the help
    of CSOM.
    There are two properties which control the access request configuration, first is "RequestAccessEnabled", a Boolean flag which turns on or off the access request feature for the site. The second property defines one or more email addresses where
    requests will be sent to. It is named "RequestAccessEmail".
    The above both properties are available for server object model but not for CSOM.
    So, is there any other workaround or way to achieve the sane in CSOM?
    Thanks,

    I don't think there is a programmatic workaround for SharePoint Online.  But the email address is just used for Notification.  Anyone with Manage Permissions can approve Access Requests.  If you create an email distribution list for the multiple
    addresses that should be notified you should be able to add the email address for the distribution list into the Access request email field using the user interface.
    Paul Stork SharePoint Server MVP
    Principal Architect: Blue Chip Consulting Group
    Blog: http://dontpapanic.com/blog
    Twitter: Follow @pstork
    Please remember to mark your question as "answered" if this solves your problem.

  • Powershell CSOM Sharepoint online list permission

    I've been writing a script to connect to SharePoint online, create a document library and add some AD accounts to the permission. I've written all the code using snippets I have found through many searches but am having an issue with the permissions part.
    All of the code is taken from this page:
    http://jeffreypaarhuis.com/2012/06/07/scripting-sharepoint-online-with-powershell-using-client-object-model/
    The only change is i'm using the get principal fun instead of the get group, but not sure if that's what has done it. I'm very new to powershell.
    I keep getting an error when adding the user and permission type to roledefinitionbinding. The error is:
    Collection has not been initialized at line 0 char 0.
    The issue is when it runs $collRoleAssign.Add($principal, $collRdb) part and stop with the error above.
    I would really appreciate a hand with this before my PC get launched out of the window.
    Thanks Mark

    Hi,
    The following code snippet for your reference:
    var login = "[email protected]";
    var password = "xxxxxx";
    var siteURL=”https://SharePointOnlineSiteUrl”;
    ClientContext ctx = new ClientContext(siteURL);
    var securePassword = new SecureString();
    foreach (char c in password)
    securePassword.AppendChar(c);
    SharePointOnlineCredentials credentials = new SharePointOnlineCredentials(login, securePassword);
    ctx.Credentials = credentials;
    Web wsite = ctx.Web;
    ctx.Load(wsite, w => w.HasUniqueRoleAssignments, w => w.RoleAssignments.Include(roleAssigned => roleAssigned.Member.Title,
    roleAssigned => roleAssigned.RoleDefinitionBindings.Include(roleDef => roleDef.Name)));
    ctx.ExecuteQuery();
    RoleAssignmentCollection rac = wsite.RoleAssignments;
    if (rac != null && rac.Count !=0)
    Console.WriteLine("Unique Permissions: " + wsite.HasUniqueRoleAssignments);
    foreach (RoleAssignment ra in rac)
    Console.WriteLine("Group Name: " + ra.Member.Title);
    foreach (RoleDefinition rd in ra.RoleDefinitionBindings)
    Console.WriteLine("Permission: " + rd.Name);
    Console.ReadKey();
    More information:
    http://social.technet.microsoft.com/wiki/contents/articles/24087.associate-permission-levels-with-sharepoint-user-groups-using-the-client-side-object-model-in-netc.aspx
    Thanks,
    Dennis Guo
    TechNet Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Dennis Guo
    TechNet Community Support

  • How to get information about cluster disk using powershell

    Hi
    How can I list all cluster disks in my Hyper-V cluster using Powershell? I see two cluster disk "Cluster Disk 1" and "Cluster Disk 1" in my cluster management console but I would like to see them using powershell.
    Kind Regards Tomasz

    http://tinyurl.com/mfro3q5
    Get-ClusterResource
    Get-ClusterQuorum
    Get-ClusterSharedVolume
    . : | : . : | : . tim

  • How to find which authentication used to site collection and site using powershell

    Hi,
    How to find  how-many web app, sitecollection, site used Windows authentication,claim authentication and classic, secure store authention , adfs authentication using powershell code in sharepoint 2013.
    If sites are used adfs authentication how to find which email id used for that.
    Thanks,

    Authentication is only defined at the Web Application level, and the only valid auth methods are Classic (Windows (Basic/NTLM/Kerberos)), Claims (Windows (Basic/NTLM/Kerberos)), FBA Claims, , SAML Claims (ADFS), and Anonymous.
    You can find out what authentication scheme(s) are enabled via:
    $wa = Get-SPWebApplication http://webApp1$wa.IisSettings["Default"] #replace with the zone name you're interested in
    The output will look similar to this:
    PS C:\Users\trevor> $wa.IisSettings["Default"]
    AuthenticationMode : Forms
    MembershipProvider : i
    RoleManager : c
    AllowAnonymous : False
    EnableClientIntegration : True
    ServerBindings : {Microsoft.SharePoint.Admini
    stration.SPServerBinding}
    SecureBindings : {}
    UseWindowsIntegratedAuthentication : True
    UseBasicAuthentication : False
    DisableKerberos : True
    ServerComment : SharePoint
    Path : C:\inetpub\wwwroot\wss\Virtu
    alDirectories\spwebapp180
    PreferredInstanceId : 42768054
    UseClaimsAuthentication : True
    ClaimsAuthenticationRedirectionUrl :
    UseFormsClaimsAuthenticationProvider : False
    FormsClaimsAuthenticationProvider :
    UseTrustedClaimsAuthenticationProvider : False
    UseWindowsClaimsAuthenticationProvider : True
    OnlyUseWindowsClaimsAuthenticationProvider : True
    WindowsClaimsAuthenticationProvider : Microsoft.SharePoint.Adminis
    tration.SPWindowsAuthenticat
    ionProvider
    ClaimsAuthenticationProviders : {Windows Authentication}
    ClaimsProviders : {}
    ClientObjectModelRequiresUseRemoteAPIsPermission : True
    UpgradedPersistedProperties : {}
    So on this Web Application in the Default Zone you can tell I have Windows Claims enabled, not using Kerberos (so using NTLM), and Trusted (SAML/ADFS) is not enabled, neither is Forms or Anonymous.
    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.

Maybe you are looking for