ForEach-Object cmdlet to loop through each list item in the array and create a site in .NET framework

Painting QR-Code in .NET framework ForEach-Object cmdlet to loop through each list item in the array and create a site

ForEach-Object cmdlet to loop through each list item in the array and create a site
QR Code Scanner In .NET Framework
Using Barcode Control SDK for Visual Studio .NET Control to generate, create, read, scan barcode image in .NET framework applications.
Encode QR-Code In .NET Framework
Using Barcode maker for Visual Studio .NET Control to generate, create Quick Response Code image in Visual Studio .NET applications.
collection based on the list item s property values
QR Recognizer In .NET
Using Barcode reader for .NET framework Control to read, scan read, scan image in .NET applications.
Create Bar Code In .NET Framework
Using Barcode creation for .NET Control to generate, create barcode image in VS .NET applications.
PS >> >> >> >> >> >> >> >> >> >> > $items | ForEach-Object { $siteName = $_["Site name"] -Replace "\W",""; $siteURL = $url + "sites/" + $siteName; $userID = $_["Site owner"] -Replace "\d*;#",""; $user = Get-SPUser -Web $url -Identity $userID; New-SPSite -url $siteURL -Name $($_["Site name"]) ` -Description $($_["Site description"]) -OwnerAlias $user -Template "STS#0"; $_["Status"] = "Created"; $_["Comment"] = "Site $siteURL created"; $_Update(); }
Barcode Decoder In VS .NET
Using Barcode decoder for .NET Control to read, scan read, scan image in .NET applications.
Printing Quick Response Code In C#.NET
Using Barcode creator for Visual Studio .NET Control to generate, create QR-Code image in .NET framework applications.
We start by replacing nonalphanumeric characters in the Site name field value using the -replace operator, which accepts regular expressions as a pattern to search for, as described in 6 The \W character represents all nonalphanumeric characters When we use Windows PowerShell to retrieve a value from a person or group field, such as the Site owner field here, the string returned contains the user s ID, followed by the ;# characters, followed by the user s display name Since we want the user login name or an SPUser object as input to the New-SPSite cmdlet, we need to replace the unwanted characters and use the Get-SPUser cmdlet The last step performed in the ForEach-Object cmdlet is updating the current item s status to Created Updating the items helps us to keep track of which items we have already processed, allowing us to rerun the script without processing the same item twice We also add a comment in the Comment field and call the Update method to commit the changes we made to the list item to the SharePoint 2010 content database
Paint QR Code ISO/IEC18004 In .NET
Using Barcode generator for ASP.NET Control to generate, create QR Code ISO/IEC18004 image in ASP.NET applications.
Encoding QR Code 2d Barcode In Visual Basic .NET
Using Barcode printer for VS .NET Control to generate, create Quick Response Code image in VS .NET applications.
11:
Generate 2D Barcode In VS .NET
Using Barcode generator for .NET Control to generate, create Matrix Barcode image in .NET framework applications.
Drawing Data Matrix ECC200 In .NET
Using Barcode creation for Visual Studio .NET Control to generate, create DataMatrix image in VS .NET applications.
Working with Site Collections
Printing Bar Code In Visual Studio .NET
Using Barcode generator for .NET Control to generate, create bar code image in VS .NET applications.
Create Intelligent Mail In .NET
Using Barcode generator for .NET framework Control to generate, create USPS OneCode Solution Barcode image in Visual Studio .NET applications.
Scripting the Site Collection Creation
Code 128C Reader In Java
Using Barcode recognizer for Java Control to read, scan read, scan image in Java applications.
Data Matrix ECC200 Decoder In VB.NET
Using Barcode decoder for VS .NET Control to read, scan read, scan image in .NET applications.
The following script contains all the code used in this solution The script also checks if the site collection already exists before adding a new site collection and adds a comment in the Comment field depending on the outcome
Code-39 Recognizer In Visual C#.NET
Using Barcode recognizer for VS .NET Control to read, scan read, scan image in Visual Studio .NET applications.
Code 128A Creator In Java
Using Barcode generation for Java Control to generate, create Code 128 Code Set B image in Java applications.
<# SYNOPSIS Automates creation of site collections based on information stored in a SharePoint 2010 list DESCRIPTION The script automates creation of site collections based on a SharePoint List containing various settings required PARAMETER listURL URL of the source list PARAMETER field Name of the field to be used for filtering items, default is set to 'Status' PARAMETER pattern Value to be used for filtering items, default is set to 'Requested' #> param( $listURL, $field = "Status", $pattern = "Requested" ) # Check if Snap-in is loaded If (-not( Get-PSSnapin | Where-Object { $_Name -eq "MicrosoftSharePointPowerShell"}) ) { Add-PSSnapin MicrosoftSharePointPowerShell; } # Convert special characters to quoted UTF-8 format $webUrl = [MicrosoftSharePointUtilitiesSPEncode]::UrlDecodeAsUrl($listUrl); # Iterate through each segment -1-(([uri]$listURL)Segments)Count | ForEach-Object { if ($spWeb -eq $null) { $webUrl = $webUrl -replace `
Code 3/9 Maker In Java
Using Barcode maker for Android Control to generate, create USS Code 39 image in Android applications.
UCC - 12 Creation In None
Using Barcode creator for Software Control to generate, create UCC - 12 image in Software applications.
PowerShell for Microsoft SharePoint 2010 Administrators
Drawing GTIN - 13 In Objective-C
Using Barcode maker for iPad Control to generate, create EAN / UCC - 13 image in iPad applications.
Printing EAN-13 In None
Using Barcode generation for Microsoft Word Control to generate, create EAN / UCC - 13 image in Microsoft Word applications.
[MicrosoftSharePointUtilitiesSPEncode]::UrlDecodeAsUrl( ([uri]$listURL)Segments[$_] ); $spWeb = Get-SPWeb -Identity $webUrl -ErrorAction SilentlyContinue } } # Get the list $spList = $spWebGetList($listURL); # Store list items in an array $items = $spListItems | Where-Object { $_[$field] -eq $pattern } # Check if the array contains information if ($items -ne $null) { # Loop through list item collection $items | ForEach-Object { # Build site URL and replace non-alphanumeric characters $siteName = $_["Site name"] -Replace "\W",""; $siteURL = $webURL + "sites/" + $siteName; # Check if site collection already exists if(Get-SPSite -Identity $siteURL -ErrorAction SilentlyContinue) { # Site already exists Write-Host "Site $siteURL already exists"; # Updating comments $_["Comment"] = "Site already exists, choose a new name"; $_Update(); } else { # Get the user ID $userID = $_["Site owner"] -Replace "\d*;#",""; # Check if User exists if( Get-SPUser -Web $webUrl -Identity $userID -ErrorAction SilentlyContinue ) { $user = Get-SPUser -Web $webUrl -Identity $userID } else { $user = New-SPUSer -Web $webUrl -UserAlias $userID }
11:
Working with Site Collections
# Create site collection New-SPSite -url $siteURL -Name $_["Site name"] ` -Description $_["Site description"] -OwnerAlias $user -Template "STS#0"; # Update the list item $_["Status"] = "Created"; $_["Comment"] = "Site $siteURL created"; $_Update(); } } } # Dispose SPWeb $spWebDispose()
This example demonstrated some of the ways you can work with SharePoint 2010 lists In 14, we will describe how to access, modify, and manage lists in more detail You can run the script against the Request Site list manually by typing the following:
PS > \Create-RequestedSitesps1 ` >> -listURL "http://nimaintranet/Lists/Request Site"
When you do not specify the field or pattern, the default values are used The script checks the list for list items where the Status field equals Requested and creates new site collections based on the list items retrieved Finally, the script updates the list items Status field to Created and adds a comment indicating the site was created in the Comment field You can also set up a scheduled task that runs the script once per day, automating the creation of new site collections
Copyright © OnBarcode.com . All rights reserved.