Added a new field (AddressLine1) to a list, and needed to display the field in all list views. It needed to always display before another field (AddressLine2).
Script below loops through all views of a list, and if the AddressLine2 field exists, it will add AddressLine1 just before it.
Note: Can’t use ForEach loop to go through each list view as the .Update() will throw an error, due to restrictions in updating collection items while enumerating.
The code below will terminate all running workflow instances for a give SPListItem.
The order in which fields are displayed in the New, Edit, and Display forms for a list item is determined by the FieldLinks order of its content type.
The SPFieldLinkCollection has a handy Reorder method that we can use to set the order of the fields, using their internal names.
The script below does this through PowerShell: