#cls
#if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {
# Add-PSSnapin Microsoft.SharePoint.PowerShell;
#}
Remove-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
try
{
#$srcListSiteUrl = "XXXXXX"
#$SourceListName = "Outlookupdate"
$dstListSiteUrl = "XXXXXXX"
$DestinationListName = "OutlookupdateReceiver"
$keyColumnInternalName = "Name";
$keyColumnInternalName2= "Status";
$keyValue2 ="Completed";
#$sourceListWeb = Get-SPWeb -identity $srcListSiteUrl
#$sourceListUrl = $sourceListWeb.ServerRelativeUrl + $SourceListName;
#$sourceListUrl = $sourceListWeb.ServerRelativeUrl + $SourceListName;
$dstListWeb = Get-SPWeb -identity $dstListSiteUrl
$destinationListUrl = $dstListWeb.ServerRelativeUrl + "/lists/" + $DestinationListName;
#$SourceList = $sourceListWeb.GetList($sourceListUrl);
$sourceWebURL = "XXXXXX/"
$sourceListName = "Outlookupdate"
$spSourceWeb = Get-SPWeb $sourceWebURL
$SourceList = $spSourceWeb.Lists[$sourceListName]
write-host $sourceListUrl
$DestinationList = $dstListWeb.GetList($destinationListUrl);
write-host "soruce destination set "
#$freq = 30 # in minutes
#$now = get-date
#$lastrun = $now.AddMinutes($freq)
$now = (Get-Date).AddDays(-1);
$lastrun_converted = [microsoft.sharepoint.utilities.sputility]::CreateISO8601DateTimeFromSystemDateTime($now);
write-host $lastrun_converted;
$camlsource = "<Where><Geq><FieldRef Name='Modified'/><Value Type='DateTime' IncludeTimeValue='True'>$lastrun_converted</Value></Geq></Where>"
#$query=new-object Microsoft.SharePoint.SPQuery
$queryfromsource=new-object Microsoft.SharePoint.SPQuery
#$query.ViewAttributes = "Scope=`"Recursive`""
$queryfromsource.ViewAttributes = "Scope=`"Recursive`""
$queryfromsource.Query=$camlsource
#$query.Query=$camlsource
#$result = $list.GetItems($query)
#$sourceSPListItemCollection = $SourceList.GetItems();
$sourceSPListItemCollection = $SourceList.GetItems($queryfromsource);
write-host $sourceSPListItemCollection.Count;
foreach($srcListItem in $sourceSPListItemCollection)
{
write-host $srcListItem
#CAML query of the common column (generally the title column or any unique column)
$keyValue = $srcListItem[$keyColumnInternalName]
write-host $keyValue
# $camlQuery = "<Where>
# <Eq>
# <FieldRef Name=" + $keyColumnInternalName + " />
# <Value Type='Text'>" + $keyValue + "</Value>
# </Eq>
# </Where>"
$camlQuery = "<Where>
<And>
<Eq>
<FieldRef Name=" + $keyColumnInternalName + " />
<Value Type='Text'>" + $keyValue + "</Value>
</Eq>
<Neq>
<FieldRef Name=" + $keyColumnInternalName2 + " />
<Value Type='Text'>" + $keyValue2 + "</Value>
</Neq>
</And>
</Where>"
$spQuery = new-object Microsoft.SharePoint.SPQuery
$spQuery.Query = $camlQuery
$spQuery.RowLimit = 1
#check if the item is already present in destination list
$destItemCollection = $DestinationList.GetItems($spQuery)
write-host "destination count"
write-host $destItemCollection.Count
if($destItemCollection.Count -gt 0)
{
write-host "list item already exists, updating "
foreach($dstListItem in $destItemCollection)
{
foreach($spField in $dstListItem.Fields)
{
if ($spField.ReadOnlyField -ne $True -and $spField.InternalName -ne "Attachments")
{
$dstListItem[$spField.InternalName] = $srcListItem[$spField.InternalName];
}
}
# Handle Attachments
write-host "Handle Attachments "
foreach($leafName in $srcListItem.Attachments)
{
write-host "inside"
#file source list
$filename1 = "http://XXXX/" + $keyValue
write-host $filename1;
$spFile = $SourceList.ParentWeb.GetFile($filename1);
$dstListItem.Attachments.Add($filename1, $spFile.OpenBinary());
}
$dstListItem["Status" ] ="Completed";
$dstListItem.Update()
}
} #if conditon end else start
else
{
write-host "adding new item"
}
}
}
catch
{ write-host $_.exception
}
finally
{
if($sourceListWeb -ne $null)
{$sourceListWeb.Dispose()}
if($dstListWeb -ne $null)
{ $dstListWeb.Dispose()}
}
Blogs about sharepoint ,Sharepoint Designer,Infopath and powershell
Subscribe to:
Post Comments (Atom)
SPFX - HTTPClient - Curd Operations - SharePoint list.
Create solution in the name of SpfxCrud. ISpfxCrudProps.ts export interface ISpfxCrudProps { description : string ; context : an...
-
$now = (Get-Date).AddDays(-1); $lastrun_converted = [microsoft.sharepoint.utilities.sputility]::CreateISO8601DateTimeFromSystemDateTime($...
-
<# The below PowerShell script enumerates through all sites with unique permissions and fetches users with Full Control Permission gran...
-
<Sharepoint:SPSecurityTrimmedControl runat="server" Permissions="ManageLists"> add the above code beofre ribbo...
No comments:
Post a Comment