Saturday, October 5, 2013

"Sign in as Different User" in SharePoint 2013

To get this feature of sign in as different user back, we can follow either permanent or temporary solution:

Permanent Solution for all web applications

1. Locate the following file and open it in a text editor: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\CONTROLTEMPLATES\Welcome.ascx

2. Add the following element before the existing "ID_RequestAccess" element:

<SharePoint:MenuItemTemplate runat="server" ID="ID_LoginAsDifferentUser" Text="<%$Resources:wss,personalactions_loginasdifferentuser%>" Description="<%$Resources:wss,personalactions_loginasdifferentuserdescription%>" MenuGroupId="100" Sequence="100" UseShortId="true" />

3. Save the file.

One time Temporary Solution 
Append /_layouts/closeconnection.aspx?loginasanotheruser=true after site url in browser's address bar.

Example: http://sp-dev-srv:7000/_layouts/closeconnection.aspx?loginasanotheruser=true

PowerShell Popup

To show a popup message in PowerShell, we need to create an object of wscript.shell and then call popup method with parameters.

Popup Syntax
popup("Message to be displayed",0, "popup window title", button type id + icon style id)

Example
$alert = new-object -comobject wscript.shell
$answer = $alert.popup("Do you want to delete these files?", 0,"Delete Files",4+32)
If ($answer -eq 6) {
  $alert.popup("You answered yes.")
} else {
  $alert.popup("You answered no.")
}

#Button Types 
#0 Show OK button
#1 Show OK and Cancel buttons
#2 Show Abort, Retry, and Ignore buttons
#3 Show Yes, No, and Cancel buttons
#4 Show Yes and No buttons
#5 Show Retry and Cancel buttons

#icon style
#16 Stop Icon
#32 Question Icon
#48 Exclamation Icon
#64 Information Icon

#return values of popup method
OK = 1
Cancel = 2
Abort = 3
Retry = 4
Ignore = 5
Yes = 6
No = 7

Delete All SharePoint List Items Using PowerShell 2010

How to delete all list items from SharePoint list?

Follow the steps to delete all list items from SharePoint List

1. Create new PowerShell (.ps1) file with below script using Notepad

$Url = "http://site-url:5000"
$ListName = "Sales 2013"
$Web = Get-SPWeb $Url
$List = $Web.lists[$ListName]

if($List -eq $null)
{    
  Write-Error "The List cannot be found";return
}

Write-Warning "Deleting all list items from $($ListName)"
$Items = $List.GetItems()
Write-Host "Total Items to be deleted : $($Items.count)"

if($Items.count -gt 0)
{
  $shell = new-object -comobject wscript.shell
  $result = $shell.popup("Total Item to be deleted : $($Items.count) `nDo   you want to continue?",0,"Alert",4+32)

if($result -eq "6")
{
foreach ($item in $Items)
{
  $itemId = $item.ID
  $List.GetItemById($itemId).Delete()
  Write-Host "Deleted list item with id $($itemId)"
}
}
}
$List.Update()
$Web.Dispose()


2. Replace values of parameters $Url and $ListName

3. Save file in server hard drive (Example: D:\PowerShell\Delete-List-Items.ps1)

4. Open "SharePoint 2010 Management Shell" with "Run as administrator"

5. Navigate to the folder where the script  file is stored
    (Example: cd D:\PowerShell)

6. Select file to be executed
    (Example: .\Delete-List-Items.ps1)

7. Press enter and enjoy!!