Quantcast
Channel: PowerShell Daily » Name
Viewing all articles
Browse latest Browse all 3

Users from AD to WSS

$
0
0

This script is copying all users which have department, title, which are enabled and copying them through the step of creating csv on disk to Windows SharePoint Services 3.0
Need to create a Contact list in Windows SharePoint Services 3.0.

#add quest snappin
add-pssnapin Quest.ActiveRoles.ADManagement

#connect to domain (I have two domains)
connect-QADService -service 'domain.com'

#users from AD to CSV
get-qaduser -enabled | select-object LastName, FirstName, Department, PhoneNumber, Pager, Mobile, Email, Title, Office, City, StreetAddress, LogonName, Name | Where-Object {$_.department} | Where-Object {$_.Title} | Sort-Object Department | Export-Csv -NoTypeInformation "D:\Scripts\contacts2wss\Contacts.csv" -Delimiter ","

#remove pluses from phonenumber
(Get-Content "D:\Scripts\contacts2wss\Contacts.csv") | Foreach-Object {$_ -replace "\+", ""} | Set-Content "D:\Scripts\contacts2wss\Contacts.csv"

#connect to sharepoint
[void][System.reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$site=new-object Microsoft.SharePoint.SPSite("http://wss/default.aspx")
$web=$site.rootweb
$splist=$web.Lists["Contact Information"]
$allitems = $splist.items;
$count=$allitems.count-1

get-date > D:\Scripts\contacts2wss\log.txt

#delete all items
for($intIndex=$count;$intIndex-gt-1;$intIndex--)
{
       "Deleting : " + $intIndex >> D:\Scripts\contacts2wss\log.txt
        $allItems.Delete($intIndex);
} 

#import csv
$records = import-csv "D:\Scripts\contacts2wss\Contacts.csv"

#add all items from csv
foreach($cmrecord in $records)
	{
        "Adding : " + $cmrecord.LastName + " " + $cmrecord.FirstName >> D:\Scripts\contacts2wss\log.txt
        $spitem = $spList.Items.Add()
        $spitem["Last Name"] = $cmrecord.LastName
        $spitem["First Name"] = $cmrecord.FirstName
        $spitem["Department"] = $cmrecord.Department
        $spitem["Phone Number"] = $cmrecord.PhoneNumber
        $spitem["Internal Phone Number"] = $cmrecord.Pager
        $spitem["Mobile Phone Number"] = $cmrecord.mobile
        $spitem["E-mail Address"] = $cmrecord.Email
        $spitem["Job Title"] = $cmrecord.Title
        $spitem["Office"] = $cmrecord.Office
        $spitem["City"] = $cmrecord.City
        $spitem["Address"] = $cmrecord.StreetAddress
        
        #taking photos
        $name = $cmrecord.LogonName
        $destination = "\\wss\Contacts\Photos\$name.jpg"
        $spitem["Photo"] = "$destination, "
        
        $spitem.Update() 
	}
Write-Host "List was recreated successfully" >> D:\Scripts\contacts2wss\log.txt
$web.Dispose()
$site.Dispose()
remove-pssnapin Quest.ActiveRoles.ADManagement

An important thing is that before setup this script you should create a list “Contact Information” from Contacts Template and add from List Settings “Add from existing site columns” all required columns to it.

In my example after connecting this list to outlook there are everything ok except photos.

P.S. I am using:

  • $Host.Version 2.0
  • Quest.ActiveRoles.ADManagement 1.3.0.1787
  • PSCX 1.2.0.0

Viewing all articles
Browse latest Browse all 3

Trending Articles