This will get the my site location for each user who has created one. It should be possible to add some logic to only display the entries that aren't NULL.
$mySiteUrl = "mysitehostURL"
$site = Get-SPSite $mySiteUrl
$context = Get-SPServiceContext $site
$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
$profiles = $profileManager.GetEnumerator()
$Profiles | select PersonalSite
This is also a great way to get other data out of the UPS. You can see a list of the available properties and methods by doing the a $profiles | get-member after using the above code. I've pasted them below for reference.
Name MemberType
---- ----------
Commit Method
CreatePersonalSite Method
Equals Method
GetChanges Method
GetColleagueChanges Method
GetCommonManager Method
GetDirectReports Method
GetEnumerator Method
GetExtendedReports Method
GetHashCode Method
GetManager Method
GetManagers Method
GetMyDirectReportOrganizations Method
GetMyOrganizationChains Method
GetMyOrganizations Method
GetPeers Method
GetProfileValueCollection Method
GetType Method
IsProfileOwner Method
RefreshManagers Method
SID Method
ToString Method
Item ParameterizedProperty
Colleagues Property
CurrentChangeToken Property
DisplayName Property
ID Property
Memberships Property
MultiloginAccounts Property
Parent Property
PersonalizationLinks Property
PersonalSite Property
PersonalUrl Property
ProfileManager Property
ProfileManagerBase Property
ProfileSubtype Property
ProfileType Property
Properties Property
PublicOrganizationViewUrl Property
PublicUrl Property
QuickLinks Property
RecordId Property
RemotePersonalSiteHostUrl Property
Suggestions Property
ViewerRights Property
Practical Kung Fu dot net
Taking over the world one atom at a time.
Wednesday, December 21, 2011
Friday, December 2, 2011
User profile pictures won't update in SharePoint 2010 (There! I fixed it!)
So I was trying to get the user's profile pictures to show up on their user profiles in SharePoint 2010. It worked great until I got to the part of running Update-SPProfilePhotoStore.
Update-SPProfilePhotoStore : Error processing the photo URL User Photos/Profile
Pictures/0c37852b-34d0-418e-91c6-2ac25af4be5b_10.jpg for user i:05.t|adfs20ser
ver|michael.tupker@company.com: System.UriFormatException: Invalid URI: A Do
s path must be rooted, for example, 'c:\'.
Um, why is it telling me that a Dos path must be rooted? I'm working with a URL here! I after much fighting and swearing at the User Profile Service and it's apparently broken powershell command. I decided to write my own version of Update-SPProfilePhotoStore. I don't think it's as robust as the one that is supposed to work, but at least now all the employees have pictures on their profiles. I still don't know why the built in cmdlet doesn't work. We are have up to the august 2011 CU installed. We had not tried running the Update-SPProfilePhotoStore cmdlet before this.
There are a few things that you will need to set.
$mySiteUrl
$upAttribute
$newpictureURL
$picturePath
As well as the searchbase on the get-aduser cmdlet.
#########Begin script
Import-Module ActiveDirectory -ErrorAction SilentlyContinue
Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
Start-SPAssignment -Global
#creates connection to UPS
$mySiteUrl = "https://mysite.corp.net"
$upAttribute = "PictureURL"
$site = Get-SPSite $mySiteUrl
$context = Get-SPServiceContext $site
$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
$profiles = $profileManager.GetEnumerator()
$newpictureURL = "https://mysite.corp.net/ADPictures/"
$picturePath = "E:\Scripts\SyncPics\ProfilePictures"
#gets all pictures from AD and save them locally
$users = Get-ADUser -Filter * -SearchBase "OU=Accounts,DC=company,DC=net" -Properties mail,thumbnailphoto
$users | foreach-object {$username = $_.mail; $_.thumbnailphoto | Set-Content $picturePath\$username.jpg -Encoding byte}
$spWeb = Get-SPWeb -Identity $mySiteUrl
$spFolder = $spWeb.GetFolder("ADPictures")
$spFileCollection = $spFolder.Files
#loops through all profiles, uploads the picture to the library and sets the profile picture
Foreach ($profile in $profiles) {
$email = $profile["workemail"].value
Write-Host $email
$file = Get-ChildItem $picturePath -filter "$email.jpg"
#check if file exists. if true upload pic to library and set picture URL
If ({Test-Path $picturePath\$email.jpg} -and $file.length -gt 1) {
$filename = $file.name
$spFileCollection.Add("ADPictures/$($filename)",$file.OpenRead(),$true)
$profile[$upAttribute].Value = $newpictureURL + $filename
$profile.Commit()
}
else {
$profile[$upAttribute].Value = $Null
$profile.Commit()
}
}
Stop-SPAssignment -Global
Update-SPProfilePhotoStore : Error processing the photo URL User Photos/Profile
Pictures/0c37852b-34d0-418e-91c6-2ac25af4be5b_10.jpg for user i:05.t|adfs20ser
ver|michael.tupker@company.com: System.UriFormatException: Invalid URI: A Do
s path must be rooted, for example, 'c:\'.
Um, why is it telling me that a Dos path must be rooted? I'm working with a URL here! I after much fighting and swearing at the User Profile Service and it's apparently broken powershell command. I decided to write my own version of Update-SPProfilePhotoStore. I don't think it's as robust as the one that is supposed to work, but at least now all the employees have pictures on their profiles. I still don't know why the built in cmdlet doesn't work. We are have up to the august 2011 CU installed. We had not tried running the Update-SPProfilePhotoStore cmdlet before this.
There are a few things that you will need to set.
$mySiteUrl
$upAttribute
$newpictureURL
$picturePath
As well as the searchbase on the get-aduser cmdlet.
#########Begin script
Import-Module ActiveDirectory -ErrorAction SilentlyContinue
Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
Start-SPAssignment -Global
#creates connection to UPS
$mySiteUrl = "https://mysite.corp.net"
$upAttribute = "PictureURL"
$site = Get-SPSite $mySiteUrl
$context = Get-SPServiceContext $site
$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
$profiles = $profileManager.GetEnumerator()
$newpictureURL = "https://mysite.corp.net/ADPictures/"
$picturePath = "E:\Scripts\SyncPics\ProfilePictures"
#gets all pictures from AD and save them locally
$users = Get-ADUser -Filter * -SearchBase "OU=Accounts,DC=company,DC=net" -Properties mail,thumbnailphoto
$users | foreach-object {$username = $_.mail; $_.thumbnailphoto | Set-Content $picturePath\$username.jpg -Encoding byte}
$spWeb = Get-SPWeb -Identity $mySiteUrl
$spFolder = $spWeb.GetFolder("ADPictures")
$spFileCollection = $spFolder.Files
#loops through all profiles, uploads the picture to the library and sets the profile picture
Foreach ($profile in $profiles) {
$email = $profile["workemail"].value
Write-Host $email
$file = Get-ChildItem $picturePath -filter "$email.jpg"
#check if file exists. if true upload pic to library and set picture URL
If ({Test-Path $picturePath\$email.jpg} -and $file.length -gt 1) {
$filename = $file.name
$spFileCollection.Add("ADPictures/$($filename)",$file.OpenRead(),$true)
$profile[$upAttribute].Value = $newpictureURL + $filename
$profile.Commit()
}
else {
$profile[$upAttribute].Value = $Null
$profile.Commit()
}
}
Stop-SPAssignment -Global
Labels:
Automation,
Script,
Sharepoint
Monday, November 14, 2011
SharePoint 2010 Backup All Site Collections in All Web applciations
So with any new SharePoint 2010 farm comes lots of powershell. Since we don't have a nice 3rd party backup solution for granular backups setup yet, I decided to write a quick script that will get all site collecitons in all web applications and back them up.
The basic flow of the script is as follows:
Update 11/14/2011: Changed loop for parsing site collections to exclude the office viewing service cache site.
The basic flow of the script is as follows:
- create directory with current date for backup set
- loop through all web apps
- loop through all site collections
- backup each site collection to a file using the site name as the file name
- write site name and URL to sitemap.txt file so there is a location record
- remove backups older than 30 days
####
#By Mike Tupker
#11/14/2011
#backups all site collections
Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
Start-SPAssignment -Global
$today = Get-Date -format "MM-dd-yyyy-HH.mm.ss"
$backuppath = "e:\backups\$today"
$logFile = "$backuppath\BackupLog.log"
try
{
#check if backup directory exist. if not create them.
if (-not (Test-Path $backuppath)) {
New-Item $backuppath -type directory
}
#loop through all web apps
foreach ($webapp in Get-SPWebApplication) {
#loop through all site in each web apps
foreach ($site in Get-SPSite -WebApplication $webapp.url -Limit all | where {$_ -notlike "*Office_Viewing_Service_Cache"}) {
#define backup name
$name = $site.RootWeb.ToSTring() + ".bak"
#backup site
Write-Host Site URL: $site.Url
Write-Host Site Name: $name
Backup-SPSite -Identity $site.Url -Path $backupPath\$name -UseSqlSnapshot
#create site map
Write-Output "$name,$site.Url" | Out-File -FilePath $backupPath\siteMap.txt -Append
}
}
#remove old backps older than 30 days
$allbackups = Get-ChildItem e:\backups
foreach($directory in $allbackups)
{
$creationdate = ((Get-Date) - $allbackups.CreationTime).Days
if ($creationdate -gt 30 -and $directory.PsISContainer -eq $True)
{$directory.Delete()}
}
}
catch
{
write-Host Backup failed. See $logFile for more information.
# Write error message to the log file
write "$today Error: $_">>$logFile
}
Stop-SPAssignment -Global Update 11/14/2011: Changed loop for parsing site collections to exclude the office viewing service cache site.
Labels:
Automation,
Script,
Sharepoint
Tuesday, November 8, 2011
Convert an Active Directory group to a SharePoint 2010 Group (ADFS email identity)
During a recent Sharepoint migration I had need to convert an AD group into a SharePoint group in SP 2010.
This script was created to also populate the email identity for using claims auth with ADFS, however it could also be moddified to work with gold old fashioned NTLM using classic or claims authentication.
import-module activedirectoryEssentially it creates an object that contains the group members. Then loops through each of them and creates an identity on the site collection (using the person's email address) then adds that user to the group.
add-pssnapin Microsoft.SharePoint.PowerShell
$users = Get-ADGroupMember -identity Groupname.Members | get-aduser -Properties mail | select-object mail
foreach ($user in $users) {
$email = $user.mail.ToString()
New-SPUser -UserAlias "i:05.t|adfs20server|$email" -Web "https://webapp/sites/site/"
Set-SPUser -identity "i:05.t|adfs20server|$email" -Web "https://webapp/sites/site/" -Group "Site Members"
}
This script was created to also populate the email identity for using claims auth with ADFS, however it could also be moddified to work with gold old fashioned NTLM using classic or claims authentication.
Labels:
Script,
Sharepoint
Monday, June 20, 2011
Vista Group Policy Preferences and Scheduled Tasks not pushing
So I had need to deploy a wireless profile (and key) to a bunch of Vista machines last week. Since group policy doesn't support pushing personal wireless encryption keys I had to do a scheduled task preference that runs a script that calls an import command. The policy worked perfectly on Windows 7 however when I tested on a Vista machine I found that no scheduled task had been created yet.
Fast forward through many hours of banging my head against the GPMC....
I called MS support and they confirmed that this is a known bug. Apparently Windows vista machines cannot have vista or later scheduled task preferences pushed to them. I was however able to get around the issue by creating a simple, XP era, task using preferences that runs at logon. For some reason the Vista client can receive that correctly.
So apparently MS is aware of the issue and they are working on a fix...(deployment date TBD....) ;)
Labels:
Group Policy,
How To,
Windows
Wednesday, May 4, 2011
Server 2008 R2 Clustering using Dynamic disks with Veritas Stoage Foundation
Ok, so after a lot of banging my head against this I finally asked one of our storage guys (thanks John). I was trying to setup a Windows 2008 R2 cluster for use as a SQL 2008 R2 cluster. However the SAN storage I was given was created as dynamic partitions which isn't natively supported in Windows clustering, but is supported using Veritas Storage Foundation.
No matter how many times you try and add a new disk to the cluster it will tell you, "No disks suitable for cluster disks were found. For diagnostic information about disks available to the cluster, use the Validate a Configuration Wizard to run Storage tests." But the validation test won't show usable storage.
First you need to make sure that the Cluster Option for Microsoft Cluster Service (MSCS)/Failover Cluster is installed in Veritas Storage Foundation. You will need a license for this feature otherwise the check box will be greyed out. The feature can be added using Programs and Features in the control panel.
To actually make the cluster see the storage you first need to create an Empty Service or Application in the Failover Cluster Manager.
For me this didn't work right away due to some sort of locking that was happening on one of the nodes. A reboot fixed that issue.
Update: 2010/05/06 - Started having some problems when bringing the Volume Manager Disk Group online. The act of bringing the resource online seems to crash the cluster! I'm currently talking with our storage team about the issue. We have identified a FUGLY work around. Put the disk group in a deported state. Then right after creating the Volume Manager Disk Group cluster resource, detach it from the cluster application so it's in available storage. Then you can bring it online...eventually. By eventually I mean that it seems to be very picky about when you enter the DiskGroupName.
We are still trying to figure out what's going on with this and will probably be contacting Symantec support on the issue due to the cluster crashing implication.
No matter how many times you try and add a new disk to the cluster it will tell you, "No disks suitable for cluster disks were found. For diagnostic information about disks available to the cluster, use the Validate a Configuration Wizard to run Storage tests." But the validation test won't show usable storage.
First you need to make sure that the Cluster Option for Microsoft Cluster Service (MSCS)/Failover Cluster is installed in Veritas Storage Foundation. You will need a license for this feature otherwise the check box will be greyed out. The feature can be added using Programs and Features in the control panel.
To actually make the cluster see the storage you first need to create an Empty Service or Application in the Failover Cluster Manager.
- Right click on Services and application
- Select more actions
- Select Create Empty Service or Application
- Right click on the clustered application you just created.
- Select Add a resource
- Select More Resources
- select 9 - Add Volume Manager Disk Group
- Right click on the disk group you just created and select properties.
- Click the properties tab.
- On the line named "DiskGroupName" Type the name of the disk group, as it appear in Veritas into the Value field.
- Click ok.
For me this didn't work right away due to some sort of locking that was happening on one of the nodes. A reboot fixed that issue.
Update: 2010/05/06 - Started having some problems when bringing the Volume Manager Disk Group online. The act of bringing the resource online seems to crash the cluster! I'm currently talking with our storage team about the issue. We have identified a FUGLY work around. Put the disk group in a deported state. Then right after creating the Volume Manager Disk Group cluster resource, detach it from the cluster application so it's in available storage. Then you can bring it online...eventually. By eventually I mean that it seems to be very picky about when you enter the DiskGroupName.
We are still trying to figure out what's going on with this and will probably be contacting Symantec support on the issue due to the cluster crashing implication.
Labels:
Clustering,
How To,
Windows
Friday, April 29, 2011
Powershell: SQL Database File Sizes Over Time
Recently I had need to track the file sizes of databases (MDF files attached to a SQL 2005 server) over time. I setup a scheduled task to run every hour which runs a powershell script. The script gets the file sizes of all MDFs in a directory on a remote computer.
#Construct the filename Date-time
$date = get-date
$filename = "MDF-{0}{1:d2}{2:d2}-{3:d2}{4:d2}.txt" -f $date.year,$date.month,$date.day,$date.hour,$date.minute
$spacestats = @()
$spacestats = Get-ChildItem "\\servernamev$\Microsoft SQL Server\MSSQL.12\MSSQL\Data" *.mdf | Select-Object Name, @{Name="Mbytes";Expression={[math]::Round($_.Length / 1Mb)}}
$spacestats | ConvertTo-Csv -NoTypeInformation | Out-File $filename
The idea is that later I'll be able to compile this historical data and track DB growth over time. It probably isn't the most elegant solution but it gets the job done.
#Construct the filename Date-time
$date = get-date
$filename = "MDF-{0}{1:d2}{2:d2}-{3:d2}{4:d2}.txt" -f $date.year,$date.month,$date.day,$date.hour,$date.minute
$spacestats = @()
$spacestats = Get-ChildItem "\\servernamev$\Microsoft SQL Server\MSSQL.12\MSSQL\Data" *.mdf | Select-Object Name, @{Name="Mbytes";Expression={[math]::Round($_.Length / 1Mb)}}
$spacestats | ConvertTo-Csv -NoTypeInformation | Out-File $filename
The idea is that later I'll be able to compile this historical data and track DB growth over time. It probably isn't the most elegant solution but it gets the job done.
Subscribe to:
Posts (Atom)