$previousRunDate = [Microsoft.SharePoint.Utilities.SPUtility]::CreateISO8601DateTimeFromSystemDateTime([DateTime]::Now.AddDays(-100)) $camlModifiedDateQuery = '<where><Gt><FieldRef Name="Modified" /><Value Type="DateTime">{0}</Value></Gt></Where>' -f $previousRunDate $query = New-Object Microsoft.SharePoint.SPQuery $query.Query = $camlQuery $listItems = $list.GetItems($query) $previousRunDate = [Microsoft.SharePoint.Utilities.SPUtility]::CreateISO8601DateTimeFromSystemDateTime([DateTime]::Now.AddDays(-100)) $camlModifiedDateQuery = '
Showing posts with label powershell. Show all posts
Showing posts with label powershell. Show all posts
Sunday, August 4, 2013
PowerShell to Find ListItems Modified Since a Date
Assuming that the list to be queried is already referenced in the $list object in script, here is a simple snippet to retrieve all list items that have been modified within the last one hundred days:
$previousRunDate = [Microsoft.SharePoint.Utilities.SPUtility]::CreateISO8601DateTimeFromSystemDateTime([DateTime]::Now.AddDays(-100)) $camlModifiedDateQuery = '<where><Gt><FieldRef Name="Modified" /><Value Type="DateTime">{0}</Value></Gt></Where>' -f $previousRunDate $query = New-Object Microsoft.SharePoint.SPQuery $query.Query = $camlQuery $listItems = $list.GetItems($query) $previousRunDate = [Microsoft.SharePoint.Utilities.SPUtility]::CreateISO8601DateTimeFromSystemDateTime([DateTime]::Now.AddDays(-100)) $camlModifiedDateQuery = '{0} ' -f $previousRunDate
$query = New-Object Microsoft.SharePoint.SPQuery
$query.Query = $camlQuery
$listItems = $list.GetItems($query)
$previousRunDate = [Microsoft.SharePoint.Utilities.SPUtility]::CreateISO8601DateTimeFromSystemDateTime([DateTime]::Now.AddDays(-100)) $camlModifiedDateQuery = '<where><Gt><FieldRef Name="Modified" /><Value Type="DateTime">{0}</Value></Gt></Where>' -f $previousRunDate $query = New-Object Microsoft.SharePoint.SPQuery $query.Query = $camlQuery $listItems = $list.GetItems($query) $previousRunDate = [Microsoft.SharePoint.Utilities.SPUtility]::CreateISO8601DateTimeFromSystemDateTime([DateTime]::Now.AddDays(-100)) $camlModifiedDateQuery = '
Wednesday, January 4, 2012
Setting BCS Secondary Fields Programmatically in SharePoint 2010
Phew, that was quite a battle. I have been writing some code to import values from a CSV file into some custom lists in SharePoint (I realise that there are, of course, plenty of other ways to import into SharePoint, such as using PowerShell or a third party app., but specific needs call for special handling), and one of the requirements is to import data into External Columns in the SharePoint list.
Original this process used the GetSecondaryFieldNames() method of the SPBusinessDataField instance to get the internal names of each of the secondary fields, and then combined each of those with the internal name of the SPBusinessDataField to create the displayname value for each secondary field. The list item fields could then be set using these displayname values.
This worked fine in the dev environment... but of course the real workd is different! Researching the failure of this process on the target machine showed that the display names for the secondary fields did not contain the values from the GetSecondaryFieldNames() call (PowerShell allowed me to easily view the Schema XML for the fields in the list, saving the need for a tool like SharePoint Manager).
So, my solution was to seek the secondary field by enumerating through all fields in the list, seeking the field whose:
Original this process used the GetSecondaryFieldNames() method of the SPBusinessDataField instance to get the internal names of each of the secondary fields, and then combined each of those with the internal name of the SPBusinessDataField to create the displayname value for each secondary field. The list item fields could then be set using these displayname values.
This worked fine in the dev environment... but of course the real workd is different! Researching the failure of this process on the target machine showed that the display names for the secondary fields did not contain the values from the GetSecondaryFieldNames() call (PowerShell allowed me to easily view the Schema XML for the fields in the list, saving the need for a tool like SharePoint Manager).
So, my solution was to seek the secondary field by enumerating through all fields in the list, seeking the field whose:
- "DisplayName" property value starts with the internal name of the related external data field
- "BdcField" property value matches a string value returned by GetSecondaryFieldNames()
Labels:
development,
powershell,
sharepoint 2010
Monday, August 30, 2010
PowerShell PS1 File Not Recognised as the Name of ....
Annoying wee behaviour - if calling a PowerShell file from a batch file, it seems that even if the BAT and PS1 files are in the same folder, and the BAT file has changed the current path to be that folder, it is still necessary to include the whole path to the PS1 file in the -command call.
The statements
cd [the folder path]
powershell -command "&{.\test.ps1}"
didn't work, whereas the following does work:
cd [the folder path]
powershell - command "&{[the folder path]\test.ps1}"
The statements
cd [the folder path]
powershell -command "&{.\test.ps1}"
didn't work, whereas the following does work:
cd [the folder path]
powershell - command "&{[the folder path]\test.ps1}"
Subscribe to:
Posts (Atom)