воскресенье, 11 сентября 2011 г.

Sort list of Views with sql method


this powershell script sort list of views without they deleting.


$SortedListUser = New-Object 'System.Collections.Generic.List[string]'
$MyPath = Read-Host "Path To File"
$MyFile = Get-Content $MyPath
foreach ($i in $MyFile) {
if($i -ne "")
{
   $SortedListUser.Add($i)
}
}
$SortedListDesc = New-Object 'System.Collections.Generic.List[string]'
for( $i = $SortedListUser.Count; $i -ge 0; $i-=1 )
{ $SortedListDesc.Add($SortedListUser[$i]) }
$Connection = New-Object System.Data.SQLClient.SQLConnection
$Connection.ConnectionString =
"Data Source=server;Initial Catalog=db ;Integrated Security=True"
$Connection.Open()
$TeamSitePrompt = Read-Host "What is the Team Site URL (i.e. http://test.com/teamsite)"
$ListNamePrompt = Read-Host "What is the List Name you want to sort"
$Web = Get-SPWeb $TeamSitePrompt
$List = $Web.Lists[$ListNamePrompt]
$Views = $List.Views
#Create a Sorted List to store the Views you want to Sort
$SortedList = New-Object 'System.Collections.Generic.List[string]'  
foreach ($CurrentItemUser in $SortedListUser)
{
foreach ($CurrentViewItem in $Views)
{

if($CurrentItemUser -eq $CurrentViewItem.Title)
{
  Write-Host $CurrentViewItem.Id
  $uslovie = $CurrentViewItem.Id
  $Command = New-Object System.Data.SQLClient.SQLCommand
  $Command.Connection = $Connection
  $Command.CommandText = "UPDATE WSS_Content.dbo.AllWebParts SET tp_CreationTime = GETDATE() Where tp_ListId ='"+$List.Id+"' AND tp_ID ='"+$CurrentViewItem.Id+"'"
  #$Command.CommandText
$Command.ExecuteNonQuery()
}
}
}
$Connection.Close()


Create txt  file, sorting name of views :
view1
view2
view3

Run script!

Комментариев нет:

Отправить комментарий