28 Şubat 2012 Salı

Getting Managed Account Password via Power Shell


I ve found this command in msdn, I could not find the link, though.

If you set changing the account password via sharepoint (automatically), you can get the managed account password by using below commands.

Get Managed Account Passwords vıa Power Shell:
function Bindings()
{
    return [System.Reflection.BindingFlags]::CreateInstance -bor
    [System.Reflection.BindingFlags]::GetField -bor
    [System.Reflection.BindingFlags]::Instance -bor
    [System.Reflection.BindingFlags]::NonPublic
}
function GetFieldValue([object]$o, [string]$fieldName)
{
    $bindings = Bindings
    return $o.GetType().GetField($fieldName, $bindings).GetValue($o);
}
function ConvertTo-UnsecureString([System.Security.SecureString]$string) 
{ 
    $intptr = [System.IntPtr]::Zero
    $unmanagedString = [System.Runtime.InteropServices.Marshal]::SecureStringToGlobalAllocUnicode($string)
    $unsecureString = [System.Runtime.InteropServices.Marshal]::PtrToStringUni($unmanagedString)
    [System.Runtime.InteropServices.Marshal]::ZeroFreeGlobalAllocUnicode($unmanagedString)
    return $unsecureString
}

Get-SPManagedAccount | select UserName, @{Name="Password"; Expression={ConvertTo-UnsecureString (GetFieldValue $_ "m_Password").SecureStringValue}}

16 Şubat 2012 Perşembe

Sharepoint Infopath getting logged in username in Forms Authentication

If you use Claims Based Auth., you cannot get a proper username with the command ın Infopath:


this.Application.User.LoginName

You ll get something like :
i:0#.|PROVIDERNAME|Username

You can replace the string but it 's not a proper way to do it.

You can use 2 methods:

1.  SPUser user = SPContext.Current.Web.CurrentUser;
user.userName would get you the proper name

or

2.

string userName = null;
SPClaimProviderManager mgr = SPClaimProviderManager.Local;
if (mgr != null)
{
       userName = mgr.DecodeClaim(SPContext.Current.Web.CurrentUser.LoginName).Value;
}

13 Şubat 2012 Pazartesi

Custom Membership provider for Sharepoint

Below you can find a good tutorial for How to add a custom membership provider to Sharepoint.

http://kidoos.net/content/SharePointCustomMemershipProvider.aspx

I m gonna try it after I have completed my provider.

Adding dll s to GAC and updating them are always seem like a dirty work : (

Before changing anything, getting an image backup would be great, I assume.

Cannot find MembershipProvider in .Net 4.0 Web.Security

Hi,

If you'd like to create a custom MembershipProvider, you need to implement MembershipProvider class.

It is usually in System.Web.Securty class, but you need to add System.Web.ApplicationServices Reference dll to get it work in .Net 4.0 !


Before .Net 4.0 it was enough to add the System.Web reference.



8 Şubat 2012 Çarşamba

InfoPath - Explorer Enhanced Security Configuration error


If you experience Internet Explorer Enhanced Security Confguration error,

You need to Close IE ESC.

To do that, Start - Control Panel - Programs and Features - Turn Windows features on or off

Or Open Server Manager

In Security Information tab you ll see IE Enhanced Security Configuration (ESC)
You should set it to Off

Sharepoint - Creating a list from excel list

7 Şubat 2012 Salı

Sharepoint 2010 - 7 Day Backup script

Hi,
I found this post very handy and updated for myself:

http://blog.integrii.net/?p=122

Just schedule this batch file to work in every day, so you ll have a backup process which keeps your backups up to 7 days. It automatically deletes the file after 7th day.


You can also create a email job and send an email with the attachment of the spbackup.txt file.


@echo off
echo ===============================================================
echo Back up the farm to D:\BAK\FarmBackup - 7 day
echo ===============================================================

REM ===============================================================
REM Variables
REM ===============================================================

set location=D:\BAK\FarmBackups
set templog=D:\BAK\FarmBackups\spbackup.txt


REM ===============================================================
REM Rename folders and delete 7th
REM ===============================================================

rmdir /s /q %location%\day7
ren %location%\day6 day7
ren %location%\day5 day6
ren %location%\day4 day5
ren %location%\day3 day4
ren %location%\day2 day3
ren %location%\day1 day2
ren %location%\today day1
mkdir %location%\today

REM ===============================================================
REM Run the Backup program
REM ===============================================================


C:
cd C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN
@echo off
stsadm.exe -o backup -directory %location%\today -backupmethod full > %templog%
echo completed

Batch file commands

I constantly searching these commands, so I decided to wrap them up in here


Some necessary commands for batch files:

Create Folder:
mkdir c:\TempFolder

Rename Folder:
Ren C:\OldFolder NewFolderName

Remove Folder:
rmdir /s /q "C:\TempFolder"


Copy Folder:
xcopy "D:\CopyFolder" "D:\PasteFolder" /s /Y


Rename File:
rename C:\OldName.txt NewName.txt


Delete File:
del C:\FileToBeDeleted.txt



Sharepoint 2010 - Scheduled Backup

It is impossible to do it via Central Administration.

To be able to schedule your backups you need to create a batch file and use Task Scheduler to schedule.

Important:
You need to use an admin account to run the batch file successfully (SP Admin account would be fine), otherwise you ll get `Access Denied` error.

Create a .bat file using notepad, paste the code below, fix the backup path (best practice would be using a shared location if you have multiple servers to backup.)



Another note:

Ex:
If you have the backup batch file in D: but stsadm.exe is on c:
Put `c:` above the line
cd %COMMONPROGRAMFILES% ...


Ex:

...
echo====..
c:
cd %COMMONPROGRAMFILES% ...
...

CODE:


@echo off
echo ===============================================================
echo Back up the farm to C:\backup
echo ===============================================================
cd %COMMONPROGRAMFILES%\Microsoft Shared\web server extensions\12\BIN
@echo off
stsadm.exe -o backup -directory "\backup" -backupmethod full
echo completed


Source:
http://technet.microsoft.com/en-us/library/cc288541(office.12).aspx


6 Şubat 2012 Pazartesi

Sharepoint 2010 import - site and list

To be able to import a site:

- Create the site by using New site, name it as the same it would be imported.
- Run the Management Shell as Admin
- Run the following command

import-spweb -identity http://contosoweb/sitename/ -path \\appserver\bu\list.cmp


To import a list:

Import-SPWeb http://contosoweb –Path D:\imports\ImportList.cmp

Sharepoint 2010 - Constantly prompting Username Password in local server.

This problem was also bugging me in Dynamics CRM.

İf you would have a server and try to access it inside, it constantly prompts you username and password.

In order to be able to solve this issue you need to add a new registry key

Run - regedit

Go to:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa


Create a DWORD (32bit) key in the folder, named as:
DisableLoopbackCheck


Set the value as:
1


Close the regisrty window. By default (and best case) it does not need any restart of iis, explorer or server.


Source:
http://www.jeremytaylor.net/2010/05/24/sharepoint-disable-loopback-check-disableloopbackcheck-dword-in-registry/

1 Şubat 2012 Çarşamba

Sharepoint 2010 - Granular Backup (site, list import & export)

Export

Go to Central Administration - Backup and Restore - Granular Backup - Export a site or list

Select the site collection - site and list, (depending on your export scope)

Give a export filename
Select export version and press Start Export.

Wait until the process is over.


Import:
Get the path of the .cmp file that you ve exported.

Open the Sharepoint 2010 Management Shell as Administrator

Type
Import-SPWeb <siteUrl> –Path <fullpath of the .cmp file>

Sample:
Import-SPWeb http://tristk004dvp:17691 –Path D:\imports\ExpenseSite.cmp


Note:
If you export-import the files between servers you can use a shared location to keep things simpler.