Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How could i apply sharepoint url credential to access the website by Powershell?
i have to apply username and password in the code.How could I apply?
PHP
if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) 
{
    Add-PSSnapin Microsoft.SharePoint.PowerShell;
}
$sourceWebURL = "http://sezmnc22787"
$sourceListName = "DL_Accounts"
$spSourceWeb = Get-SPWeb $sourceWebURL
$spSourceList = $spSourceWeb.Lists[$sourceListName]
If(!($spSourceList  -eq $null)){
$spSourceItems = $spSourceList.GetItems()
$spSourceItems | ForEach-Object {
$Username=$_['AccountName']
$Username=$Username.Substring($Username.IndexOf("#")+1)
$Group = [ADSI]"LDAP://CN=CMIT, CN=Users, DC=env, DC=com"
$User = [ADSI]"LDAP://CN=$Username, CN=Users, DC=env, DC=com"
If ($Group.IsMember($User.ADsPath) -eq $False)
{
    $Group.Add($User.ADsPath)
}
}
}
Posted
Updated 24-Apr-13 5:17am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900