Question

After created site collection in PowerShell with this command:

 $SiteCollection = New-SPSite -Url $WebAPP.Url -OwnerAlias $SiteColl_Owner -Language 1033 -Template $SiteColl_Template -Name $SiteColl_Name

I want to use SPSite object without Get-SPSite

$spListCollection = $SiteCollection.Lists 

foreach($List in $SiteCollLists.List) 
{ 
   $ListTemplate = $SiteCollection.ListTemplates[$List.Template] 
   $spListCollection.Add($List.Name, $List.Name, $ListTemplate) 
}

Error is:

Cannot index into a null array. At C:\Users\mmma\Desktop\CreatePortal\TestCreateInfra.ps1:69 char:8 + $ListTemplate = $SiteCollection.ListTemplates[$List.Template] + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : NullArray

Était-ce utile?

La solution

I can only assume that $SiteCollection = New-SPSite ... after successful creation of new site it's not returning site object to $SiteCollection variable.

So, try to $SiteCollection = Get-SPSite *newsiteurl* after creation.

As per MSDN documentation there is NO site return type for New-SPSite.

Autres conseils

Site collections do not have lists, webs do.

$SiteCollection = New-SPSite ...

$myWeb = $SiteCollection.RootWeb
$spListCollection = $myWeb.Lists 

foreach($List in $SiteCollLists.List) 
{ 
   ...
}

Same thing is true of ListTemplates. That is a property of the root web object.

Your code looks like it's trying to duplicate every list from one web to another. Keep in mind that a new site starts with a number of visible and hidden lists, and your code would try to duplicate all of them. A new STS#0 Team Site starts with these.

Title
-----
appdata
Composed Looks
Content type publishing error log
Converted Forms
Documents
Form Templates
List Template Gallery
Master Page Gallery
MicroFeed
Project Policy Item List
Site Assets
Site Pages
Solution Gallery
Style Library
TaxonomyHiddenList
Theme Gallery
User Information List
Web Part Gallery
wfpub
Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top