Welcome to my blog which is mostly dedicated to SharePoint, there are few other random topics as well.
Tuesday, April 12, 2016
Set people picker at web application level
#Get WebApplication name where you want to fix this issue
$webApp = Get-SPWebApplication http://server:port
# we need to repeat the following block for all the domains you want People Picker to work for on this particular web app
# ——————————————————————————————————————————
$domainInfo = new-object Microsoft.SharePoint.Administration.SPPeoplePickerSearchActiveDirectoryDomain
$domainInfo.DomainName ='domain.net'; # specify the fqdn
$domainInfo.ShortDomainName ='domain'; # specify the netbios name
# =====================================
# This section is only required if there is a one-way trust to the domain and the application pool account does not have access
# First you have to run setapppassword on every server in the farm.
# This sets the encryption key used with the password you enter for the account you specify for $newdomain.loginname
stsadm -o setapppassword -password "Password"
# Where <password> is any string you want to use as an encryption key.
# This needs to be run on every server using the same value for <password>
$domainInfo.loginname = 'domain\sp_farm' # Specify an account that has access to the remote domain
# Do not change anything in the next two lines, it will prompt you to enter the password.
[System.Security.SecureString]$secureStringValue = Read-Host “Enter the account password: ” -AsSecureString
$domainInfo.setpassword($secureStringValue)
# =====================================
$webApp.PeoplePickerSettings.SearchActiveDirectoryDomains.Add($domainInfo)
# Repeat end
# ——————————————————————————————————————————-
# Finally save settings for the web app
$webApp.update()
$webApp = Get-SPWebApplication http://server:port
# we need to repeat the following block for all the domains you want People Picker to work for on this particular web app
# ——————————————————————————————————————————
$domainInfo = new-object Microsoft.SharePoint.Administration.SPPeoplePickerSearchActiveDirectoryDomain
$domainInfo.DomainName ='domain.net'; # specify the fqdn
$domainInfo.ShortDomainName ='domain'; # specify the netbios name
# =====================================
# This section is only required if there is a one-way trust to the domain and the application pool account does not have access
# First you have to run setapppassword on every server in the farm.
# This sets the encryption key used with the password you enter for the account you specify for $newdomain.loginname
stsadm -o setapppassword -password "Password"
# Where <password> is any string you want to use as an encryption key.
# This needs to be run on every server using the same value for <password>
$domainInfo.loginname = 'domain\sp_farm' # Specify an account that has access to the remote domain
# Do not change anything in the next two lines, it will prompt you to enter the password.
[System.Security.SecureString]$secureStringValue = Read-Host “Enter the account password: ” -AsSecureString
$domainInfo.setpassword($secureStringValue)
# =====================================
$webApp.PeoplePickerSettings.SearchActiveDirectoryDomains.Add($domainInfo)
# Repeat end
# ——————————————————————————————————————————-
# Finally save settings for the web app
$webApp.update()
Friday, April 10, 2015
list all site collections in all databases of database server using Powershell
Someone asked me how to retrieve list of all site collection residing in all content database of a database server. So have prepared a small script for this...
To Get the list of server execute below command
Get-SPServer
Above command will list all server in the farm.
Copy the SQL/Database server you intend to query...
$DBServerInstance = "XXXXXXXX"
Replace xxxx with the database server name/Alias if you are using alias.
$dbserver = Get-SPDatabase –ServerInstance $DBServerInstance
To Get the list of server execute below command
Get-SPServer
Above command will list all server in the farm.
Copy the SQL/Database server you intend to query...
$DBServerInstance = "XXXXXXXX"
Replace xxxx with the database server name/Alias if you are using alias.
$dbserver = Get-SPDatabase –ServerInstance $DBServerInstance
foreach ($db in $dbserver)
{
$db
Get-SPSite –ContentDatabase $db – Limit all | Select URL
}
You can redirect the output of foreach loop contents to a text file.
Wednesday, February 5, 2014
Download all InfoPath within SharePoint Web Application using PowerShell
Below PowerShell script can be used to download/Backup all infoPath forms residing within a Web Application with a folder structure similar to the URL.
========================================================================
#Change below url to your web app URL
$SPWebApp = Get-SPWebApplication ('https://YourWebApplication.com/')
$destination = "d:\\temp\\InfoPathBackup\\"
"Site Name`tList Name`tUrl`tDocs`tLast Mod`tWF`tLive WF`tLive WF Names`tTemplate" > d:\temp\AllIPDocLibs.csv
#loop through each site in the site collection
$cnt = $SPWebApp.Sites.count.toString()
"Total Site collection -: $cnt "
foreach ($SPSite in $SPWebApp.Sites) #loop through all site collection
{
$cnt = $SPSite.allwebs.count.toString()
"Total number of Sites in collection -: $cnt "
$SiteTitle = $SPSite.url.toString()
"PROCESSING Site collection $SiteTitle"
$url = $SiteTitle
$req = [system.Net.WebRequest]::Create($url)
$req.UseDefaultCredentials = $true
try {
$res = $req.GetResponse()
} catch [System.Net.WebException] {
$res = $_.Exception.Response
}
if ( $res.StatusCode -eq "OK" )
{
$ErrorActionPreference="SilentlyContinue"
foreach($webs in $SPSite.allwebs)
{
#use this for output
$webTitle = $webs.title.toString()
"PROCESSING site $webTitle"
#loop though each list in the current website
for($i=0;$i -ne $webs.lists.count;$i++)
{
$list = $webs.lists[$i]
#this is used for output and to make the code a little more readable
$listTitle = $list.toString()
$listUrl = $list.DefaultViewUrl
$listCount = $list.ItemCount
if( $list.BaseType -eq "DocumentLibrary" -and
$list.BaseTemplate -eq "XMLForm")
{
$listModDate = $list.LastItemModifiedDate.ToShortDateString()
$listTemplate = $list.ServerRelativeDocumentTemplateUrl
$listWorkflowCount = $list.WorkflowAssociations.Count
$listLiveWorkflowCount = 0
$listLiveWorkflows = ""
foreach ($wf in $list.WorkflowAssociations)
{
if ($wf.Enabled)
{
$listLiveWorkflowCount++
if ($listLiveWorkflows.Length -gt 0)
{
$listLiveWorkflows = "$listLiveWorkflows, $($wf.Name)"
}
else
{
$listLiveWorkflows = $wf.Name
}
}
}
"$webTitle`t$listTitle`t$listUrl`t$listCount`t$listModDate`t$listWorkflowCount`t$listLiveWorkflowCount`t$listLiveWorkflows`t$listTemplate" >> d:\temp\AllIPDocLibs.csv
#Downloading file to local drive
#Ensure destination directory
$destinationfolder = $destination + "/" + $listUrl.Substring(0,$listUrl.LastIndexOf("/"))
$file.Name = $listTemplate.Substring($listTemplate.LastIndexOf("/") + 1)
if (!(Test-Path -path $destinationfolder))
{
$dest = New-Item $destinationfolder -type directory
}
#Download file
$binary = $file.OpenBinary()
$stream = New-Object System.IO.FileStream($destinationfolder + "/" + $file.Name), Create
$writer = New-Object System.IO.BinaryWriter($stream)
$writer.write($binary)
$writer.Close()
}
}
$webs.Dispose()
}
}
else
{ Add-Content d:\temp\DeadSites.txt "`n $SiteTitle" } #dead or inaccessible sites encountered during loop.
$SPSite.Dispose()
}
[GC]::Collect()
#Dispose of the site object
$SPWebApp.Dispose()
"Done"
========================================================================
========================================================================
#Change below url to your web app URL
$SPWebApp = Get-SPWebApplication ('https://YourWebApplication.com/')
$destination = "d:\\temp\\InfoPathBackup\\"
"Site Name`tList Name`tUrl`tDocs`tLast Mod`tWF`tLive WF`tLive WF Names`tTemplate" > d:\temp\AllIPDocLibs.csv
#loop through each site in the site collection
$cnt = $SPWebApp.Sites.count.toString()
"Total Site collection -: $cnt "
foreach ($SPSite in $SPWebApp.Sites) #loop through all site collection
{
$cnt = $SPSite.allwebs.count.toString()
"Total number of Sites in collection -: $cnt "
$SiteTitle = $SPSite.url.toString()
"PROCESSING Site collection $SiteTitle"
$url = $SiteTitle
$req = [system.Net.WebRequest]::Create($url)
$req.UseDefaultCredentials = $true
try {
$res = $req.GetResponse()
} catch [System.Net.WebException] {
$res = $_.Exception.Response
}
if ( $res.StatusCode -eq "OK" )
{
$ErrorActionPreference="SilentlyContinue"
foreach($webs in $SPSite.allwebs)
{
#use this for output
$webTitle = $webs.title.toString()
"PROCESSING site $webTitle"
#loop though each list in the current website
for($i=0;$i -ne $webs.lists.count;$i++)
{
$list = $webs.lists[$i]
#this is used for output and to make the code a little more readable
$listTitle = $list.toString()
$listUrl = $list.DefaultViewUrl
$listCount = $list.ItemCount
if( $list.BaseType -eq "DocumentLibrary" -and
$list.BaseTemplate -eq "XMLForm")
{
$listModDate = $list.LastItemModifiedDate.ToShortDateString()
$listTemplate = $list.ServerRelativeDocumentTemplateUrl
$listWorkflowCount = $list.WorkflowAssociations.Count
$listLiveWorkflowCount = 0
$listLiveWorkflows = ""
foreach ($wf in $list.WorkflowAssociations)
{
if ($wf.Enabled)
{
$listLiveWorkflowCount++
if ($listLiveWorkflows.Length -gt 0)
{
$listLiveWorkflows = "$listLiveWorkflows, $($wf.Name)"
}
else
{
$listLiveWorkflows = $wf.Name
}
}
}
"$webTitle`t$listTitle`t$listUrl`t$listCount`t$listModDate`t$listWorkflowCount`t$listLiveWorkflowCount`t$listLiveWorkflows`t$listTemplate" >> d:\temp\AllIPDocLibs.csv
#Downloading file to local drive
#Ensure destination directory
$destinationfolder = $destination + "/" + $listUrl.Substring(0,$listUrl.LastIndexOf("/"))
$file.Name = $listTemplate.Substring($listTemplate.LastIndexOf("/") + 1)
if (!(Test-Path -path $destinationfolder))
{
$dest = New-Item $destinationfolder -type directory
}
#Download file
$binary = $file.OpenBinary()
$stream = New-Object System.IO.FileStream($destinationfolder + "/" + $file.Name), Create
$writer = New-Object System.IO.BinaryWriter($stream)
$writer.write($binary)
$writer.Close()
}
}
$webs.Dispose()
}
}
else
{ Add-Content d:\temp\DeadSites.txt "`n $SiteTitle" } #dead or inaccessible sites encountered during loop.
$SPSite.Dispose()
}
[GC]::Collect()
#Dispose of the site object
$SPWebApp.Dispose()
"Done"
========================================================================
Get list of all InfoPath forms (with URL/Path) within a Web application-SharePoint using PowerShell
Below script helps to get list of infopath forms within a web application with their path/URL. Script also collects the names of dead/inaccessible sites (which the scripts encounters during the looping of all site collections within the web application) and outputs into a text file.
========================================================================
#change the URL to match web application where you would like to search InfoPath forms
$SPWebApp = Get-SPWebApplication ('http://yourwebapplication.com/')
"Site Name`tList Name`tUrl`tDocs`tLast Mod`tWF`tLive WF`tLive WF Names`tTemplate" > d:\temp\AllIPDocLibs.csv
#Loop through each site in the site collection
$cnt = $SPWebApp.Sites.count.toString()
"Total Site collection -: $cnt "
foreach ($SPSite in $SPWebApp.Sites) #loop through all site collection
{
$cnt = $SPSite.allwebs.count.toString()
"Total number of Sites in collection -: $cnt "
$SiteTitle = $SPSite.url.toString()
"Processing Site collection $SiteTitle"
$url = $SiteTitle
$req = [system.Net.WebRequest]::Create($url)
$req.UseDefaultCredentials = $true
try {
$res = $req.GetResponse()
} catch [System.Net.WebException] {
$res = $_.Exception.Response
}
if ( $res.StatusCode -eq "OK" )
{
$ErrorActionPreference="SilentlyContinue"
foreach($webs in $SPSite.allwebs)
{
#use this for output
$webTitle = $webs.title.toString()
"PROCESSING site $webTitle"
#loop though each list in the current website
for($i=0;$i -ne $webs.lists.count;$i++)
{
$list = $webs.lists[$i]
#variables for output.
$listTitle = $list.toString()
$listUrl = $list.DefaultViewUrl
$listCount = $list.ItemCount
if( $list.BaseType -eq "DocumentLibrary" -and
$list.BaseTemplate -eq "XMLForm")
{
$listModDate = $list.LastItemModifiedDate.ToShortDateString()
$listTemplate = $list.ServerRelativeDocumentTemplateUrl
$listWorkflowCount = $list.WorkflowAssociations.Count
$listLiveWorkflowCount = 0
$listLiveWorkflows = ""
foreach ($wf in $list.WorkflowAssociations)
{
if ($wf.Enabled)
{
$listLiveWorkflowCount++
if ($listLiveWorkflows.Length -gt 0)
{
$listLiveWorkflows = "$listLiveWorkflows, $($wf.Name)"
}
else
{
$listLiveWorkflows = $wf.Name
}
}
}
"$webTitle`t$listTitle`t$listUrl`t$listCount`t$listModDate`t$listWorkflowCount`t$listLiveWorkflowCount`t$listLiveWorkflows`t$listTemplate" >> d:\temp\AllIPDocLibs.csv
}
}
$webs.Dispose()
}
}
else
{ Add-Content d:\temp\DeadSites.txt "`n $SiteTitle" }
$SPSite.Dispose()
}
[GC]::Collect()
#Dispose of the site object
$SPWebApp.Dispose()
"Done"
========================================================================
========================================================================
#change the URL to match web application where you would like to search InfoPath forms
$SPWebApp = Get-SPWebApplication ('http://yourwebapplication.com/')
"Site Name`tList Name`tUrl`tDocs`tLast Mod`tWF`tLive WF`tLive WF Names`tTemplate" > d:\temp\AllIPDocLibs.csv
#Loop through each site in the site collection
$cnt = $SPWebApp.Sites.count.toString()
"Total Site collection -: $cnt "
foreach ($SPSite in $SPWebApp.Sites) #loop through all site collection
{
$cnt = $SPSite.allwebs.count.toString()
"Total number of Sites in collection -: $cnt "
$SiteTitle = $SPSite.url.toString()
"Processing Site collection $SiteTitle"
$url = $SiteTitle
$req = [system.Net.WebRequest]::Create($url)
$req.UseDefaultCredentials = $true
try {
$res = $req.GetResponse()
} catch [System.Net.WebException] {
$res = $_.Exception.Response
}
if ( $res.StatusCode -eq "OK" )
{
$ErrorActionPreference="SilentlyContinue"
foreach($webs in $SPSite.allwebs)
{
#use this for output
$webTitle = $webs.title.toString()
"PROCESSING site $webTitle"
#loop though each list in the current website
for($i=0;$i -ne $webs.lists.count;$i++)
{
$list = $webs.lists[$i]
#variables for output.
$listTitle = $list.toString()
$listUrl = $list.DefaultViewUrl
$listCount = $list.ItemCount
if( $list.BaseType -eq "DocumentLibrary" -and
$list.BaseTemplate -eq "XMLForm")
{
$listModDate = $list.LastItemModifiedDate.ToShortDateString()
$listTemplate = $list.ServerRelativeDocumentTemplateUrl
$listWorkflowCount = $list.WorkflowAssociations.Count
$listLiveWorkflowCount = 0
$listLiveWorkflows = ""
foreach ($wf in $list.WorkflowAssociations)
{
if ($wf.Enabled)
{
$listLiveWorkflowCount++
if ($listLiveWorkflows.Length -gt 0)
{
$listLiveWorkflows = "$listLiveWorkflows, $($wf.Name)"
}
else
{
$listLiveWorkflows = $wf.Name
}
}
}
"$webTitle`t$listTitle`t$listUrl`t$listCount`t$listModDate`t$listWorkflowCount`t$listLiveWorkflowCount`t$listLiveWorkflows`t$listTemplate" >> d:\temp\AllIPDocLibs.csv
}
}
$webs.Dispose()
}
}
else
{ Add-Content d:\temp\DeadSites.txt "`n $SiteTitle" }
$SPSite.Dispose()
}
[GC]::Collect()
#Dispose of the site object
$SPWebApp.Dispose()
"Done"
========================================================================
Find last login timestamp for service/user account from Active directory using PowerShell
Below script will be helpful in finding the last login timestamp of the users/service accounts used by SharePoint farm. This script helps us in identifying orphan accounts which can deleted or reused elsewhere.
Logic of this script is pretty simple. Read the XML file having list of Active directory accounts. Loop through each domain controller and check and compare for the value of lastlogin with other DC. the one with the highest value is the last login timestamp value for that account. Finally the output of this is stored in a txt file.
============PowerShell Script================================================
Import-Module ActiveDirectory
$Path = "D:\Sharepoint\Lastlogintimestamp\sharepointUsers.xml"
# load it into an XML object:
$xml = New-Object -TypeName XML
$xml.Load($Path)
# note: if your XML is malformed, you will get an exception here
# always make sure your node names do not contain spaces
$rsltObj = New-Object PSObject;
$results = @();
$hostname ="";
$user =$Null;
# simply traverse the XML nodes and loop through account names:
foreach ($node in $xml.Accounts.ChildNodes)
{
$username = $node.InnerText;
write-host "Checking last login time for.... $username `n";
$dcs = Get-ADDomainController
$time = 0
foreach($dc in $dcs)
{
$hostname = $dc.HostName
$user = Get-ADUser $userName | Get-ADObject -Server $hostname -Properties lastLogon;
if( $user -ne $Null)
{
if($user.LastLogon -gt $time)
{
$time = $user.LastLogon
$hostname = $dc.HostName
}
}
}
$dt = [DateTime]::FromFileTime($time)
$rsltObj= "$username last logged on at: $dt authenticated by $hostname `n";
write-host $rsltObj;
$results += $rsltObj;
}
$results | Out-File C:\temp\SharePoint-Lastlogintimestamp.txt;
Write-host "Data saved in c:\temp\SharePoint-Lastlogintimestamp.txt";
========================================================================
===================XML File format========================================
<?xml version="1.0" encoding="UTF-8" ?>
<Accounts>
<Name>SP_Farm</Name>
<Name>SP_Service</Name>
<Name>SP_Search</Name>
</Accounts>
======================================================================
You can add more XML nodes to xml file to add more accounts which you would like to check.
Thursday, June 27, 2013
How to check If blackberry phone is unlocked
To determine if your BlackBerry is "unlocked" for use on carriers other than for which it is branded:
1. On your BlackBerry, go to Options > Advanced Options > Sim Card.
2. At that screen type MEPD (see note below) on your keyboard. A new menu will pop up.
* If your BlackBerry has a SureType keyboard (71xx and 81xx devices) you will need to double-tap the P, so the actual keys entered become M E P P D.
3. Look for Network in the list.
4. If your device is "unlocked", it should say Disabled or Inactive. If it says Active, it's still locked to that carrier.
1. On your BlackBerry, go to Options > Advanced Options > Sim Card.
2. At that screen type MEPD (see note below) on your keyboard. A new menu will pop up.
* If your BlackBerry has a SureType keyboard (71xx and 81xx devices) you will need to double-tap the P, so the actual keys entered become M E P P D.
3. Look for Network in the list.
4. If your device is "unlocked", it should say Disabled or Inactive. If it says Active, it's still locked to that carrier.
Subscribe to:
Posts (Atom)
