1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | ############################################################### #Script Function : Script will fetch the GUID and Document Name for Null DOCID, #Developed: Sanjiv kumar ################################################################ If ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) { Add-PSSnapIn -Name Microsoft.SharePoint.PowerShell } #Get SPWeb and Our List we are targeting. try { $web = Get-SPWeb "http://sp2010:23934/" $list = $web.Lists["Resumes"] $Datetime= Get-Date -Format dd_MM_yyyy_HH.mm.ss #Log file for Missing DocID $LogFileName=([string]::Concat("Output_DocID_Missing_Log " , $Datetime ,".csv")) New-Item .\$LogFileName -ItemType file #Log file for Error $LogFileName_Error=([string]::Concat("Error_DocID_Missing_Log " , $Datetime ,".txt")) New-Item .\$LogFileName_Error -ItemType file Add-Content .\$LogFileName -Value $webUrl Add-Content .\$LogFileName -Value "Number of Folders : $folderscount" Add-Content .\$LogFileName -Value ([string]::Concat("GUID_Name" +","+ "File_Name")) #Build Query $spQuery = New-Object Microsoft.SharePoint.SPQuery #CAML Query Using a DateTime Value and and Offset of Today $query = '' $spQuery.ViewAttributes = "Scope = 'Recursive'" $spQuery.Query = $query $spQuery.RowLimit = $list.ItemCount $spListItemCol = $list.GetItems($spQuery) #Writting the data to CSV foreach ($item in $spListItemCol) { #write-host "PD GUID:" $item["PDIGUID"] "File Name:" $item["Name"] -ForegroundColor Green Add-Content .\$LogFileName -Value ([string]::Concat($item["PDIGUID"] +","+ $item["Name"])) } $web.Dispose() } catch [System.Exception] { #write-host -f red $_.Exception.ToString() #write-host -f red $_.Exception.Message #write-host -f red $Error[0].Exception.Message #$ErrorVar= $_.Exception.ToString() Add-Content .\$LogFileName_Error -Value ([string]::Concat("************************************")) Add-Content .\$LogFileName_Error -Value ([string]::Concat("System Message: "+ $ErrorVar)) #Add-Content .\$LogFileName_Error -Value ([string]::Concat("System Message: "+ $Error[0])) #Add-Content .\$LogFileName_Error -Value ([string]::Concat("System Message: "+ $_.Exception.ItemName)) Add-Content .\$LogFileName_Error -Value ([string]::Concat("************************************")) continue } Remove-PSSnapin Microsoft.SharePoint.PowerShell |
Tuesday, April 28, 2015
Powershell Script to fetch the GUID and Document Name for Null DOCID
Wednesday, April 22, 2015
PowerShell to get list of SharePoint Folders Names , Files counts and File Name in the CSV format
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") $webUrl ="http://sp2010:23934/TEST" # Weburl till the Library $listName = "TEST" # Document Library Name $destination=".\" $Datetime= Get-Date -Format dd_MM_yyyy_HH.mm.ss $LogFileName=([string]::Concat("DPN_LogFile " , $Datetime ,".csv")) New-Item .\$LogFileName -ItemType file "variable initialization completed.." $sc = New-Object Microsoft.SharePoint.SPSite($webURL) $web = $sc.OpenWeb() $list = $web.Lists[$listName] $folderscount = 0 $folderswithresumes =0 $filesCount =0 $folderscount = $list.Folders.Count Add-Content .\$LogFileName -Value $webUrl Add-Content .\$LogFileName -Value "Number of Folders : $folderscount" Add-Content .\$LogFileName -Value ([string]::Concat("GUID_Name" +","+ "Files_Count"+","+ "File_Name")) #Folder Name in each of the folder foreach ($folder in $list.Folders) { $FileNames="" $foldFirstLvl = $list.ParentWeb.GetFolder($web.Url + "/" + $list.RootFolder.Url + "/" + $folder.Name) $filesCount = $foldFirstLvl.Files.Count #File Counts from each SP folder foreach ($file in $foldFirstLvl.Files) { $FileNames = $FileNames + ","+ $file.Name } $FileNames = $FileNames.trim(",") Add-Content .\$LogFileName -Value ([string]::Concat($folder.Name +","+ $filesCount +","+ $FileNames)) } $web.Dispose() |
PowerShell to delete the SPFolder from the SharePoint Document Library using input CSV file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | $snapinName = "Microsoft.SharePoint.PowerShell" if ((Get-PSSnapin | Where-Object {$_.Name -eq $snapinName }) -eq $NULL) { write-host "SharePoint SnapIn not loaded. Loading..." Add-PSSnapin $snapinName -ErrorAction SilentlyContinue } #Change the URL for different environment. #$webUrl = "http://usdttdevbq005:1000/sites/Test/" #$listUrl = "http://usdttdevbq005:1000/sites/Test/Resumes/" $webUrl = "http://sp2010:23934/" $listUrl = "http://sp2010:23934/TEST/" $destination=".\" $Datetime= Get-Date -Format dd_MM_yyyy_HH.mm.ss $InputCSVFile=".\Input_GUID.csv" #Log file name $LogFileName=([string]::Concat("Output_GRR_Bulk_DeleteFolder_Log" , $Datetime ,".txt")) $ListOfGuidNotFound="" Try { # Start Try New-Item .\$LogFileName -ItemType file "variable initialization completed.." Add-Content .\$LogFileName -Value "---> variable initialization completed.." $web = Get-SPWeb -Identity $webUrl $list = $web.GetList($listUrl) "Document Library access.." Add-Content .\$LogFileName -Value "---> Document Library access.." $userGUIDCollection=import-Csv $InputCSVFile | where {$_.key -eq $keyword} |select UserGUID "Read the CSV.." Add-Content .\$LogFileName -Value "---> Read the CSV.." #Main start #Download files in folders foreach($VaruserGUID in $userGUIDCollection) { "working for CSV GUID : " + $VaruserGUID.UserGUID.Trim().ToString() Add-Content .\$LogFileName -Value ([string]::Concat("`r`n---> working for CSV GUID : ",$VaruserGUID.UserGUID.Trim().ToString())) $varTemp = 0 foreach ($folder in $list.Folders) {# Start of For If($VaruserGUID.UserGUID.Trim().ToString() -eq $folder.DisplayName.Trim().ToString()) { "GUID Matches : " + $VaruserGUID.UserGUID.Trim().ToString() Add-Content .\$LogFileName -Value ([string]::Concat("---> GUID Matches with Resume folder name : "+ $VaruserGUID.UserGUID.Trim().ToString() )) $list.Folders.DeleteItemById($folder.ID) Add-Content .\$LogFileName -Value ([string]::Concat("---> Folder has been deleted for : "+ $VaruserGUID.UserGUID.Trim().ToString() )) $varTemp = 1 } }#End of For If($varTemp -eq 0) # Checking that the GUID is found in Resume folder, Yes or No { $ListOfGuidNotFound = $ListOfGuidNotFound.Trim().ToString() +"`r`n"+ $VaruserGUID.UserGUID.Trim().ToString() } } Add-Content .\$LogFileName -Value ([string]::Concat("`r`n*******START*** GUID Not Matches with Resume folder for GUID Start***********`r`n"+ $ListOfGuidNotFound +"*******END*** GUID Not Matches with Resume folder for GUID END***********`r`n")) } # End Try catch { $ErrorMessage = $_.Exception.Message Add-Content .\$LogFileName -Value ([string]::Concat("************************************")) Add-Content .\$LogFileName -Value ([string]::Concat("**********Error with writing files to folder*******************")) Add-Content .\$LogFileName -Value ([string]::Concat("System Message: ",$ErrorMessage)) Add-Content .\$LogFileName -Value ([string]::Concat("************************************")) continue } |
Powershell to create SharePoint folder in SharePoint Library with adding two different set of files
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | #Create Folder from the given Range and copy the file # Keep the file in C:\mydoc.txt $snapinName = "Microsoft.SharePoint.PowerShell" if ((Get-PSSnapin | Where-Object {$_.Name -eq $snapinName }) -eq $NULL) { write-host "SharePoint SnapIn not loaded. Loading..." Add-PSSnapin $snapinName -ErrorAction SilentlyContinue } $webUrl = "http://sp2010:23934/" $listName = "TEST" #Document Library $StartCounterGUID=1000; #Starting Folder number $EndCounterGUID = 1003; #End Folder number Try { # Start Try # Open web and library $web = Get-SPWeb $webUrl $list = $web.Lists[$listName] # Create desired number of subfolders for($i=$StartCounterGUID; $i -le $EndCounterGUID; $i++) { $folder = $list.AddItem("", [Microsoft.SharePoint.SPFileSystemObjectType]::Folder, "$i") $folder.Update() $spFolder = $web.GetFolder("$listName\$i") # Get the file on Disk that we want to upload $file = Get-Item C:\mydoc.txt # upload the file. write-host "$listName\$i\mydoc.txt" [Microsoft.SharePoint.SPFile]$spFile = $spFolder.Files.Add("$i"+"mydoc.txt",$file.OpenRead(),$false) $spFile.Item["Title"] = "$i"+"mydoc.txt" $spFile.Item.Update() write-host "$listName\$i\yourdoc.doc" [Microsoft.SharePoint.SPFile]$spFile = $spFolder.Files.Add("$i"+"yourdoc.doc",$file.OpenRead(),$false) $spFile.Item["Title"] = "$i"+"yourdoc.doc" #$spFile.Item["GUID"] = "$i"+"yourdoc.doc" $spFile.Item.Update() write-host $i } $web.Dispose() } catch { $web.Dispose() write-host "Web Disposed" $ErrorMessage = $_.Exception.Message write-host $ErrorMessage continue } |
Monday, March 9, 2015
Host header for SiteCollection in SharePoint 2010/ 2013
New-SPSite 'http://HR.MiracleInformatics.com' -HostHeaderWebApplication 'http://Win2012:1000' -Name 'HR Site' -Description 'Customer root' -OwnerAlias 'Miracle\administrator' -language 1033 -Template 'STS#0'
Thursday, March 27, 2014
SharePoint Device channel
You can check the SharePoint website into different browser :
Http://domain.com/?DeviceChannel=WindowsPhone
*Where WindowsPhone is the alias name given , While creating a new Device channel.
Know user agent:
http://whatsmyuseragent.com/
Http://domain.com/?DeviceChannel=WindowsPhone
*Where WindowsPhone is the alias name given , While creating a new Device channel.
Know user agent:
http://whatsmyuseragent.com/
SharePoint ECMA Scripts
Create List
<script type="text/javascript">
var clientContext = null;
var web = null;
ExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js");
function Initialize()
{
clientContext = new SP.ClientContext.get_current();
web = clientContext.get_web();
var itemCreateInfo = new SP.ListItemCreationInformation();
var listCreationInfo = new SP.ListCreationInformation();
listCreationInfo.set_title('My Custom Generic List');
listCreationInfo.set_templateType(SP.ListTemplateType.genericList);
this.oList = web.get_lists().add(listCreationInfo);
clientContext.load(oList, 'Title', 'Id');
clientContext.executeQueryAsync(Function.createDelegate(this, this.onListCreateSuccess),
Function.createDelegate(this, this.onQueryFailed));
}
function onListCreateSuccess(sender, args) {
alert("List title : " + this.oList.get_title() + "; List ID : "+ this.oList.get_id());
}
function onQueryFailed(sender, args) {
alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}</script>
Delete List
<script type="text/javascript">
var clientContext = null;
var web = null;
ExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js");
function Initialize()
{
clientContext = new SP.ClientContext.get_current();
web = clientContext.get_web();
this.list = web.get_lists().getByTitle('My custom generic list');
list.deleteObject();
clientContext.executeQueryAsync(Function.createDelegate(this, this.onListDeleteSuccess),
Function.createDelegate(this, this.onQueryFailed));
}
function onListDeleteSuccess(sender, args) {
alert("list deleted");
}
function onQueryFailed(sender, args) {
alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}</script>
Delete site :
<script type="text/javascript">
var clientContext = null;
var web = null;
ExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js");
function Initialize()
{
clientContext = new SP.ClientContext.get_current();
web = clientContext.get_web();
this.website = web.get_webs().getByTitle('Rare Solutions');
website.deleteObject();
clientContext.executeQueryAsync(Function.createDelegate(this, this.onSiteDeleteSuccess),
Function.createDelegate(this, this.onQueryFailed));
}
function onSiteDeleteSuccess(sender, args) {
alert("site deleted");
}
function onQueryFailed(sender, args) {
alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}</script>
Load List Item:
<script type="text/javascript">
var clientContext = null;
var web = null;
ExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js");
function Initialize()
{
clientContext = new SP.ClientContext.get_current();
web = clientContext.get_web();
var list = web.get_lists().getByTitle("Pages");
var camlQuery = new SP.CamlQuery();
var q = '<View><RowLimit>5</RowLimit></View>';
camlQuery.set_viewXml(q);
this.listItems = list.getItems(camlQuery);
clientContext.load(listItems, 'Include(DisplayName,Id)');
clientContext.executeQueryAsync(Function.createDelegate(this, this.onListItemsLoadSuccess),
Function.createDelegate(this, this.onQueryFailed));
}
function onListItemsLoadSuccess(sender, args) {
var listEnumerator = this.listItems.getEnumerator();
//iterate though all of the items
while (listEnumerator.moveNext()) {
var item = listEnumerator.get_current();
var title = item.get_displayName();
var id = item.get_id();
alert("List title : " + title + "; List ID : "+ id);
}
}
function onQueryFailed(sender, args) {
alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}</script>
Update List Item:
<script type="text/javascript">
var clientContext = null;
var web = null;
ExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js");
function Initialize()
{
clientContext = new SP.ClientContext.get_current();
web = clientContext.get_web();
this.list = web.get_lists().getByTitle('My custom generic list');
list.set_description('My custom generic list description');
list.update();
clientContext.load(list, 'Description');
clientContext.executeQueryAsync(Function.createDelegate(this, this.onSiteLoadSuccess), Function.createDelegate(this, this.onQueryFailed));
}
function onSiteLoadSuccess(sender, args) {
alert("list description : " + this.list.get_description());
}
function onQueryFailed(sender, args) {
alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}</script>
Create Site:
<script type="text/javascript">
var clientContext = null;
var web = null;
ExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js");
function Initialize()
{
clientContext = new SP.ClientContext.get_current();
web = clientContext.get_web();
var webCreateInfo = new SP.WebCreationInformation();
webCreateInfo.set_description("All about Rare solutions.");
webCreateInfo.set_language(1033);
webCreateInfo.set_title("Rare Solutions - SharePoint and .NET");
webCreateInfo.set_url("RareSolutionsSharePoint");
webCreateInfo.set_useSamePermissionsAsParentSite(true);
webCreateInfo.set_webTemplate("BLOG#0");
this.oNewWebsite = this.web.get_webs().add(webCreateInfo);
clientContext.load(this.oNewWebsite, 'ServerRelativeUrl', 'Created');
clientContext.executeQueryAsync(Function.createDelegate(this, this.onCreateWebSuccess),
Function.createDelegate(this, this.onQueryFailed));
}
function onCreateWebSuccess(sender, args) {
alert("Web site url : " + this.oNewWebsite.get_serverRelativeUrl());
}
function onQueryFailed(sender, args) {
alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}</script>
Delete ListItem :
<script type="text/javascript">
var clientContext = null;
var web = null;
ExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js");
function Initialize()
{
clientContext = new SP.ClientContext.get_current();
web = clientContext.get_web();
this.list = web.get_lists().getByTitle('My custom generic list');
this.oListItem = list.getItemById(1);
oListItem.deleteObject();
clientContext.executeQueryAsync(Function.createDelegate(this, this.onListItemDeleteSuccess),
Function.createDelegate(this, this.onQueryFailed));
}
function onListItemDeleteSuccess(sender, args) {
alert("list item deleted");
}
function onQueryFailed(sender, args) {
alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}</script>
Load List Data:
<script type="text/javascript">
var clientContext = null;
var web = null;
ExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js");
function Initialize()
{
clientContext = new SP.ClientContext.get_current();
web = clientContext.get_web();
this.list = web.get_lists().getByTitle("Images");
clientContext.load(list, 'Title', 'Id');
clientContext.executeQueryAsync(Function.createDelegate(this, this.onListLoadSuccess),
Function.createDelegate(this, this.onQueryFailed));
}
function onListLoadSuccess(sender, args) {
alert("List title : " + this.list.get_title() + "; List ID : "+ this.list.get_id());
}
function onQueryFailed(sender, args) {
alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}</script>
Load Site Data:
<script type="text/javascript">
var clientContext = null;
var web = null;
ExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js");
function Initialize()
{
clientContext = new SP.ClientContext.get_current();
web = clientContext.get_web();
clientContext.load(web, 'Title');
clientContext.executeQueryAsync(Function.createDelegate(this, this.onSiteLoadSuccess), Function.createDelegate(this, this.onQueryFailed));
}
function onSiteLoadSuccess(sender, args) {
alert("site title : " + web.get_title());
}
function onQueryFailed(sender, args) {
alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}</script>
Update List Item :
<script type="text/javascript">
var clientContext = null;
var web = null;
ExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js");
function Initialize()
{
clientContext = new SP.ClientContext.get_current();
web = clientContext.get_web();
this.list = web.get_lists().getByTitle('My custom generic list');
this.oListItem = list.getItemById(1);
oListItem.set_item('Title', 'Praveen Battula Updated');
oListItem.update();
clientContext.executeQueryAsync(Function.createDelegate(this, this.onUpdateListItemSuccess), Function.createDelegate(this, this.onQueryFailed));
}
function onUpdateListItemSuccess(sender, args) {
alert("list item updated");
}
function onQueryFailed(sender, args) {
alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}</script>
Subscribe to:
Posts (Atom)
HTML
Script: