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

5/17/12

Programmatically Change Sharepoint Web Application IP Address


Recently I was asked about changing a Sharepoint Web Application IP Addresses programatically, is this possible and how will it affect the Sharepoint sites?

I did some testing and it turns out that it is indeed possible to change the IIS Website IP Address without impacting the Sharepoint Web Application(s). For the most part Sharepoint does not care about the IP Address that are assigned to it's Web Application(s), what it cares about is how the IIS sites are mapped to it's Site Collections. The mapping is done via host header in IIS and Alternate Access Mappings in Sharepoint.

Hopefully there are no Sharepoint sites that are accessed using IP Addresses, if so when the IP Address changes, things will break.

Using  Host Headers and Alternate Access Mappings allow access via friendly names, these names are only bound by DNS so as

To create a friendly name like 'Portal' first I'll create a host header in IIS to my Sharepoint site, host headers allow me to have several IIS sites and only require one IP address.

In IIS select the Sharepoint site and click Bindings from the Actions menu, enter a friendly name, in my case 'Portal'



 Next Ill create a new A record on my DNS server so that the name Portal resolves to my Sharepoint Web Applications IP Address.

Next I'll create a Sharepoint Alternate Access Mapping so that Sharepoint knows what to do when it receives a request for this friendly name 'Portal'

Open Sharepoint Central Administration, select Application Management and under Web Applications select configure alternate access mappings.

Select the alternate access mapping collection for your site and select edit public URLs


Next add the url for your friendly name in one of the zone text boxes


After this configuration is complete Sharepoint can be accessed by typing http://portal. Next I want to programmatically change the IP address of my Sharepoint Web Application.

I found a Powershell script to perform this exact task.


$oldIp = "172.16.3.214"
$newIp = "172.16.3.215"


# Get all objects at IIS://Localhost/W3SVC
$iisObjects = new-object `
    System.DirectoryServices.DirectoryEntry("IIS://Localhost/W3SVC")


foreach($site in $iisObjects.psbase.Children)
{
    # Is object a website?
    if($site.psbase.SchemaClassName -eq "IIsWebServer")
    {
    $siteID = $site.psbase.Name


    # Grab bindings and cast to array
    $bindings = [array]$site.psbase.Properties["ServerBindings"].Value


    $hasChanged = $false
    $c = 0


    foreach($binding in $bindings)
    {
    # Only change if IP address is one we're interested in
    if($binding.IndexOf($oldIp) -gt -1)
    {
    $newBinding = $binding.Replace($oldIp, $newIp)
    Write-Output "$siteID: $binding -> $newBinding"


    $bindings[$c] = $newBinding
    $hasChanged = $true
    }
    $c++
    }


    if($hasChanged)
    {
    # Only update if something changed
    $site.psbase.Properties["ServerBindings"].Value = $bindings


    # Comment out this line to simulate updates.
    $site.psbase.CommitChanges()


    Write-Output "Committed change for $siteID"
    Write-Output "========================="
    }
    }
}

Note: Remember DNS will have to be changed first to accommodate the IP Address change.

Provided there are multiple IP Addresses available on the Sharepoint server, this script will look for an old IP Address and update the IIS website to the new IP Address. Again Sharepoint does not care about the IP Address but it only cares about the request coming to it via IIS and matching the name with a Site Collection.

Hopefully this is helpful, it can be useful in fail over scenarios where re-iping at the fail over site is required.

10/26/11

Sharepoint 2010 Service Pack 1 (SP1) improvements, fixes, updates


Overview of SharePoint Server 2010 SP1 improvements

  • Recycle bin: Lets you restore a site collection or a web that was deleted.
    • Service Pack 1 will introduce long awaited Site Recycle Bin functionality that enables self-service recovery of site collections and sites.   In the past IT Professionals were tasked with restoring entire databases to recover deleted site collections and sites and would generally require expensive restore environments to support the task.  Now in Service Pack 1 administrators can quickly and easily recover site collections and sites accidentally deleted by their owners in a process similar to that of the Recycle Bin we have for Lists, Libraries, and Documents.
  • Remote Backup Systems (RBS) and shallow copy can decrease downtime and increase efficiency by moving pointers to databases instead of moving databases.
    • If you’re using Remote BLOB Storage you’ve probably realized that when moving Site Collections (Move-SPSite) between content databases each unit of unstructured data (BLOB) was round tripped (I.e. uploaded and subsequently downloaded again) serially during the move.  This operation was both time consuming and resource intensive.  In Service Pack 1 we reduce that overhead by enabling “shallow copy” when moving Site Collections between databases where Remote BLOB Storage is used.  New Shallow Copy functionality with the Move-SPSite CmdLet enables moving site collections between content databases without moving the underlying unstructured data, i.e. Microsoft Word documents, PowerPoint Presentations, etc. significantly increasing performance and reliability for organizations using Remote BLOB Storage by simply updating the pointers to those objects in the destination content database.
  • You can see which folders are taking up valuable space with the improved Storage Management feature in site settings.
    • In SharePoint 2010 we removed StorMan.aspx (Storage Space Allocation) (see http://support.microsoft.com/kb/982587/EN-US) which in previous versions of SharePoint enabled granular management and insight into storage.  For example, the page would show you the top 100 documents or document libraries in terms of size.  With that information end users could the page to clean up content from their site(s) by deleting the large content that they no longer needed.  In Service Pack 1 we are bringing back an improved StorMan.aspx, enabling users to better understand where their quota is going and act upon that information to reduce the size of their sites.
  • Support for Microsoft SQL Server 2011.
  • A more robust Search Host Distribution service that improves error recovery and performance during the search crawl.
  • Adds backup and restore functionality to recover deleted site collections and webs.
  • Cascading filters in PerformancePoint Services: Filters values can now be passed from one filter to the next.
  • Support for Google Chrome - Very excited about this one!
  • Improved support for Internet Explorer 9.
  • Project Professional now synchronizes scheduled tasks with SharePoint task lists
The recommended order of installation is as follows:

You can then run the Configuration Wizard (PSConfig) one time on all boxes.

New Sharepoint Powershell Cmdlets


  • Add-SPProfileLeader -  Add a user as the company leader, make sure the CEOs pages are top in the search results, note: requires a full crawl be performed before results are seen.

  • Get-SPProfileLeader - Displays the company leader

  • Remove-SPProfileLeader - Removes the company leader

  • Remove-SPProfileSyncConnection - Make it easier to manage sync connections, link between the User Profile Synchronization Service (UPS) and the connected directory services

  • Add-SPProfileSyncConnection - Make it easier to manage sync connections


  • Disable-SPHealthAnalysisRule - Disables health analyzer rules 

  • Enable-SPHealthAnalysisRule - Enables health analyzer rules

  • Get-SPHealthAnalysisRule - Displays a health analyzer rule

  • Get-SPDeletedSite - Use this cmdlet to display a list of deleted site collections by using the identity parameter, if no parameter is specified then all deleted site collections in the farm are displayed

  • Remove-SPDeletedSite - Use this cmdlet to permanently remove a deleted site collection from the farm

  • Restore-SPDeletedSite - Restore a previously deleted site collection

  • Move-SPSocialComments - Move social comments from one page to another


  • Download Links for 2010 Service Pack 1

    Access 2010 Runtime SP1
    Access Database Engine 2010 SP1
    FAST Search Server 2010 for SharePoint SP1
     
    Groove Server 2010 SP1
     
    Office 2010 Filter Pack SP1
    Office 2010 Language Pack SP1
    Office 2010 SP1
    Office Language Interface Pack 2010 SP1
    Office Proofing Tools 2010 SP1
    Office Web Apps 2010 SP1
     
    PowerPoint Viewer SP1
     
    Project 2010 SP1
    Project Server 2010 SP1
     
    Search Server 2010 SP1
     
    Server Language Pack SP1
     
    SharePoint 2010 Indexing Connector for Documentum SP1
     
    SharePoint Designer 2010 SP1
    SharePoint Foundation 2010 Client Object Model Redistributable SP1
    SharePoint Foundation 2010 Language Pack SP1
     
    SharePoint Foundation 2010 SP1
     
    SharePoint Server 2010 SP1
    Visio 2010 SP1
    Visio Viewer 2010 SP1

    8/14/11

    Call a SQL Stored Procedure from Powershell with a parameter

    Recently I had to write a Powershell script that iterates a text file of user names and calls a stored procedure  to delete users from a database. The text file just contains account names on each line and must be in the same directory as the Powershell script.



    $conn = new-Object System.Data.SqlClient.SqlConnection("Data Source=databaseservername;User ID=sa; Password=password; Initial Catalog=databasename")
    foreach ($user in Get-Content “UserList.txt”)

    {
    $conn.Open() | out-null
    $cmd = new-Object System.Data.SqlClient.SqlCommand("SP_DeleteUser_By_AccountName", $conn)

    $cmd.CommandType = [System.Data.CommandType]::StoredProcedure
    $cmd.Parameters.Add("@AccountName",[system.data.SqlDbType]::VarChar) | out-Null

    $cmd.Parameters['@AccountName'].Direction = [system.data.ParameterDirection]::Input

    $cmd.Parameters['@AccountName'].value = $user


    $cmd.ExecuteNonQuery()
    $conn.Close()


    }

    8/12/11

    Update Sharepoint Domain Group Name attribute after migrate

    If you migrate a Sharepoint Farm into a new domain and use the STSADM -o migrategroup command it does not update the name attribute. The LoginName attribute will be correctly updated. The following Powershell script was written to address this.


    The script only updates the display name of the groups, does not alter any security permissions and only looks for Domain Groups with "OLDDOMAINNAME\" in the name attribute.

    The script copies the Domain Group LoginName attribute and replaces the name attribute with that value.

    The script accepts a URL parameter and will get the web application for the URL you pass in and iterate all the sites in that web application.



    [Reflection.Assembly]::Load("Microsoft.SharePoint, Version=12.0.0.0, Culture=Neutral, PublicKeyToken=71e9bce111e9429c")
    #enter a site URL
    $siteUrl = Read-Host "Enter Site URL"
    $rootSite = New-Object Microsoft.SharePoint.SPSite($siteUrl)
    # Get the web application for that site URL
    $spWebApp = $rootSite.WebApplication
    # Iterate the sites for the web application
    foreach($site in $spWebApp.Sites)
        {
    # Iterate the users/groups for that site
    $group = $site.RootWeb.SiteUsers
    foreach ($grp in $group)
    {
    # Ensure the item is a domain group
    if($grp.IsDomainGroup -eq "True")
    {
    $groupname = $grp.name
    if($groupname.Contains("OLDDOMAINNAME\"))
    {
    $grp.name = $grp.LoginName
    $grp.Update()
    $outputText = "$spaceBuffer$BUFFER_CHARS<Group>" + $grp.LoginName + "   --Updated"
    Write-Output $outputText
    }
    }
    }
    }