Showing posts with label Powershell. Show all posts
Showing posts with label Powershell. Show all posts

Wednesday, September 25, 2013

SharePoint 2010 - Update People Profiles Telephone Numbers With Powershell

A task was assigned to me to update 5000 telephone numbers in SharePoint..... easiest method to script and read from CSV - as so .....


Input file format (CSV) - Important note the headers have to be exactly whats in script

ntname,number
domain\smith,898021889
domain\brown,78798798

Script to read through and update WorkPhone 

#First load the SharePoint commands 
#add-PSSnapIn Microsoft.SharePoint.PowerShell

#Set up the job variables 
$csvfile="TelephoneNumbers.csv" 
$mySiteUrl = "<mysiteurl>
$upAttribute = "WorkPhone"

#Connect to User Profile Manager service 
$site = Get-SPSite $mySiteUrl 
$context = Get-SPServiceContext $site 
$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context) 

#Create Lists from each item in CSV file 
$csvData = Import-Csv $csvfile 

#Now iterate through the list to update the attribute with new value 
foreach ($line in $csvData)

    #Check to see if user profile exists 
    if ($profileManager.UserExists($line.NTName)) 
        { 
            #Get user profile and change the value 
            $up = $profileManager.GetUserProfile($line.NTName) 
 #           $up[$upAttribute].Value = $line.PropertyVal 
  $up[$upAttribute].Value = $line.number
            $up.Commit() 
        } 
    else 
    { 
        write-host "Profile for user"$line.NTName "cannot be found" 
    } 


#Dispose of site object 
$site.Dispose()

SharePoint 2010 - Object Cache: The super user account utilized by the cache is not configured.

Following error is appearing as warning on Web front ends 

Object Cache: The super user account utilized by the cache is not configured. This can increase the number of cache misses, which causes the page requests to consume unneccesary system resources.
 To configure the account use the following command 'stsadm -o setproperty -propertyname portalsuperuseraccount -propertyvalue account -url webappurl'. The account should be any account that has Full Control access to the SharePoint databases but is not an application pool account.
 Additional Data:
 Current default super user account: SHAREPOINT\system

If you think that having object caching isn't going to cause an issue with content use the following to resolve

1. Verify that you have the following administrative credentials:
To create the user accounts in Central Administration, you must be a member of the Farm Administrators group on the computer that is running the SharePoint Central Administration Web site.
2. On the Central Administration Web site, in the Application Management section, click Manage web applications.
3. Click the name of the Web application that you want to configure.
4. On the Web Applications tab, in the Policy group, click User Policy.
5. In the Policy for Web Application window, click Add Users.
6. From the Zones list, select All zones, and then click Next.
7. In the Users box, type the user name for the Portal Super User account. - domain\spsuperuser
8. Click the Check Names icon to ensure that the account name can be resolved by the authentication providers on the application server.
9. In the Choose Permissions section, check the Full Control - Has full control box.
10. Click Finish.
11. Repeat Steps 5 through 8 for the Portal Super Reader account.
12. In the Choose Permissions section, check the Full Read - Has full read-only access box. - domain\spsuperreader
13. Click Finish.
14. Make note of how the names for the Object Cache Super Reader and Object Cache Super User accounts are displayed in the User Name column. The displayed strings will be different depending on whether you are using claims authentication for the Web application.

Powershell to run 

$wa = Get-SPWebApplication -Identity "<App Identity from IIS>"
$wa.Properties["portalsuperuseraccount"] = "domain\spsuperuser"
$wa.Properties["portalsuperreaderaccount"] = "doamin\spsuperreader"

$wa.Update()

And to rollback ....

$wa = Get-SPWebApplication “http://urlofthewebapplication”
$wa.Properties.Remove("portalsuperuseraccount")
$wa.Properties.Remove("portalsuperreaderaccount")

$wa.Update()





Powershell Script to Connect to Domain Controllers

We have been seeing some issues with our servers not being able to connect to DC's - to help diagnose the issues the following scripts were useful 

This gets all the DC's and pings

[System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain() | % { $_.DomainControllers } | %{Test-Connection $_.Name}

The next one-liner connects to each of the DC's on 389

[System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain() | % { $_.DomainControllers } | %{$o=new-object Net.Sockets.TcpClient;$o.Connect( $_.IPAddress, 389); new-object PSObject -Property @{name=$_.Name;connected=$o.Connected}}

Friday, March 2, 2012

SharePoint 2010 - Powershell Installation Script

Following is a script I used for install 2010 onto farm - really simple - installs SharePoint 2010 , goes thorough initial wizard sets up CA on port 2222, installs basic features and services and then disables loopback.
Before running update the parameters in red




# Execute setup.exe with the setupfarmsilent xml to install SharePoint
#Write-Host "Installing SharePoint 2010 Quietly"
#& ‘C:\install\sp2010i\setup.exe’ ‘/config’ ‘C:\install\config.xml’ | out-null
# Include the SharePoint cmdlets
Write-Host "Loading SharePoint 2010 PowerShell cmdlets"
Add-PsSnapin Microsoft.SharePoint.PowerShell
# Set the farm variables
Write-Host "Setting SharePoint 2010 Farm variables"
$sp_cfdatabasename = "SP2010_Config"
$sp_cadatabasename = "SP2010_Admin_Content"
$sp_databaseserver = "<add databaseserver>"
$sp_passphrase = (ConvertTo-SecureString "<add passphrase>" -AsPlainText -force)
$sp_password = (ConvertTo-SecureString "<add password>" -AsPlainText -force)
$sp_username = "<add username>"


# Clean up the credentials
$sp_credentials = New-Object System.Management.Automation.PsCredential $sp_username,$sp_password
# Execute the config wizard
Write-Host "Add configuration and administration databases"
New-SPConfigurationDatabase -DatabaseName $sp_cfdatabasename -DatabaseServer $sp_databaseserver -AdministrationContentDatabaseName $sp_cadatabasename -Passphrase $sp_passphrase -FarmCredentials $sp_credentials
# Provision a Central Administration Site
Write-Host "Add Central Administration"
New-SPCentralAdministration -Port 2222 -WindowsAuthProvider "NTLM"
# Install all of the help files within Central Admin
Write-Host "Installation of Help files"
Install-SPApplicationContent
# Secure the files and registry entries on the server 
Write-Host "Resource security"
Initialize-SPResourceSecurity
# to install the features on the server. 
Write-Host "Installation of features"
Install-SPFeature -AllExistingFeatures
# to install and and then provision the services onto the farm.
Install-SPService
# Disable the loopback check, run this command from PowerShell.
Write-Host "DisableLoopbackCheck registry key"
New-ItemProperty HKLM:\System\CurrentControlSet\Control\Lsa -Name "DisableLoopbackCheck"  -value "1" -PropertyType dword
Write-Host "Installation script is complete"