Saturday, May 13, 2017

Running PowerShell Scripts in MOSS 2007 Server

Hi Folks,

I worked on a Proof of Concept to read all the user's usernames and their email addresses from a MOSS 2007 site. I've gone through many blogs where it mentioned to install Microsoft PowerShell 1.0. But believe me, it can work even with 'Windows PowerShell ISE' available in Start >> All Programs >> Accessories >> Windows PowerShell >> Windows PowerShell ISE. You need to run the scripts in the MOSS 2007 Server where your MOSS 2007 site is hosted.

I prefer you to read the below blog to set up PowerShell in MOSS 2007 Server.

https://nickgrattan.wordpress.com/2007/09/03/preparing-powershell-for-sharepoint-and-moss-2007/

You need to load file Microsoft.PowerShell_profile.ps1 before running the below script UserProfiles.ps1

[string]$FileName = ".\UsersList.csv"
$FileHeader = '"UserName", "Email"'
Add-Content -path $FileName -value $FileHeader
$site = New-Object Microsoft.SharePoint.SPSite("http://localhost/sites/intranet")
$groups = $site.RootWeb.sitegroups
foreach ($grp in $groups) {
foreach ($user in $grp.users) {
$UserEntry = '"'+ $user.name +'" ,+ "'+ $user.Email+'"'
Add-Content -path $FileName -value $UserEntry
} }
$site.Dispose()

This script also writes Usernames and Email Addresses to a CSV file.

The below mentioned link helped me to write the above script.
http://techtrainingnotes.blogspot.in/2010/12/sharepoint-powershell-script-to-list.html


Thanks,

No comments:

Post a Comment