- Open the PowerShell management shell with administrative rights.
- Run the below command in powershell
- Get-SPServiceApplicationPool | select Id, Name
Thursday, 2 June 2016
SharePoint 2103: Powershell command to get IIS application pool name from GUID
Monday, 28 March 2016
SharePoint2013: PowerShell Script to find data based on column value in list/Library
cls
if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {
Add-PSSnapin Microsoft.SharePoint.PowerShell;
}
$weburl = "http://YourSite"
$listname = "Your SharePoint List/Library"
$Column = "List/Library Column"
$web = get-spweb $weburl
$list = $web.lists[$listname]
$listItems = $list.Items| where {$_['Your List/Library Column Name'] -eq 'Your List/Library Column value'}
$listItems | ForEach-Object {
Write-Host $_.name
}
cls
if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {
Add-PSSnapin Microsoft.SharePoint.PowerShell;
}
$weburl = "http://YourSite"
$listname = "Your SharePoint List/Library"
$Column = "List/Library Column"
$web = get-spweb $weburl
$list = $web.lists[$listname]
$listItems = $list.Items| where {$_['Your List/Library Column Name'] -eq 'Your List/Library Column value'}
$listItems | ForEach-Object {
Write-Host $_.name
}
Thursday, 28 January 2016
Do NOT do this on a production server directly. Try to run in Development environment.
Run Powershell : Run the command Get-SPUsageDefinition
It will shows all the things that are retained, and for how long.
Change retention days 3 from 14 by using following PowerShell command:
The next time the Usage Log File timer jobs run it’ll clean out everything more than 3 days old. If we want to manually trigger those jobs we can use this PowerShell:
It will take some time to clear the Audit data table.
Another way:
Below is the script to delete records for particular site:
Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$site = Get-SPSite -Identity "Your Site"
$date = Get-Date
$date = $date.AddDays(-3)
#Delete Audit logs
$site.Audit.DeleteEntries($date)
|
Sunday, 24 January 2016
SharePoint 2013 Powershell script to update document library column (choice field category) when any folder created in Document Library
Scenario : My client wants to update a document library column(selected as choice category) whenever a folder is added in document library he wants that folder name should be added in category menu also.
Below is the tested SharePoint 2013 script
--------------------------------------------------------------------------------------------------------
Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$web=Get-spweb "Your site collection"
$list=$web.Lists.TryGetList("Your document library")
$i=0
$RootFolder=$web.GetFolder("Your document library")
foreach($folder in $RootFolder.SubFolders)
{
$ChoiceField = $list.Fields.GetField("Your column where category filed needs to be added") #Get the field
if($folder.Name -ne "Forms")
{
$fname= $folder.Name
if($ChoiceField.Choices.Contains($fname))
{
#write-host $ChoiceField.Choices.Item($i)
}
else
{
$ChoiceField.Choices.Add($fname)
}
}
$i=$i+1
$ChoiceField.update()
}
----------------------------------------------------------------------------------------------------------------------
Scenario : My client wants to update a document library column(selected as choice category) whenever a folder is added in document library he wants that folder name should be added in category menu also.
Below is the tested SharePoint 2013 script
--------------------------------------------------------------------------------------------------------
Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$web=Get-spweb "Your site collection"
$list=$web.Lists.TryGetList("Your document library")
$i=0
$RootFolder=$web.GetFolder("Your document library")
foreach($folder in $RootFolder.SubFolders)
{
$ChoiceField = $list.Fields.GetField("Your column where category filed needs to be added") #Get the field
if($folder.Name -ne "Forms")
{
$fname= $folder.Name
if($ChoiceField.Choices.Contains($fname))
{
#write-host $ChoiceField.Choices.Item($i)
}
else
{
$ChoiceField.Choices.Add($fname)
}
}
$i=$i+1
$ChoiceField.update()
}
----------------------------------------------------------------------------------------------------------------------
SharePoint 2013 PowerShell script to create sub folder in Document Library.
Note : Tested in SharePoint 2013
Script will get the date from server and create the sub folder in library named as server date.
Below is the script:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Get the Web
$web=Get-spweb "Your Site Collection"
#Get the List/Library
$list=$web.Lists.TryGetList("Your Document Library Name")
$RootFolder=$web.GetFolder("Your Root Folder name")
$foldername = Get-Date -Format "yyyy-MM-dd"
foreach( $folder in $RootFolder.SubFolders )
{
if($folder.name -ne "Forms")
{
$Subfolder = $list.ParentWeb.GetFolder($folder.URL + "/" + "$foldername");
#write-host $Subfolder
if ($Subfolder.Exists -eq $false)
{
#Create a Sub-Folder Inside "Sales Documents"
$Subfolder = $list.AddItem($folder.URL, [Microsoft.SharePoint.SPFileSystemObjectType]::Folder, "$foldername")
$Subfolder.Update();
Write-host "Sub-Folder created successfully"
}
else
{
write-host "Sub-Folder already exists"
}
}
}
Note : Tested in SharePoint 2013
Script will get the date from server and create the sub folder in library named as server date.
Below is the script:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Get the Web
$web=Get-spweb "Your Site Collection"
#Get the List/Library
$list=$web.Lists.TryGetList("Your Document Library Name")
$RootFolder=$web.GetFolder("Your Root Folder name")
$foldername = Get-Date -Format "yyyy-MM-dd"
foreach( $folder in $RootFolder.SubFolders )
{
if($folder.name -ne "Forms")
{
$Subfolder = $list.ParentWeb.GetFolder($folder.URL + "/" + "$foldername");
#write-host $Subfolder
if ($Subfolder.Exists -eq $false)
{
#Create a Sub-Folder Inside "Sales Documents"
$Subfolder = $list.AddItem($folder.URL, [Microsoft.SharePoint.SPFileSystemObjectType]::Folder, "$foldername")
$Subfolder.Update();
Write-host "Sub-Folder created successfully"
}
else
{
write-host "Sub-Folder already exists"
}
}
}
Subscribe to:
Posts (Atom)