Tuesday, April 19, 2011

Faster VMWare

I was struggeling with the slowliness of my VMWare Workstation machine. I gave it 12 GB ram and 4 core processors
.
Well it turned out that assigning it more processors, actually made it slower. I reduced the processor to 1
 
I also modified some settings in the config.ini located in c:\programmdata\vmware\vmware workstation\
(This file might not exist if you have the default settings, so make any kind of settings in the VMWare to make the file appear)

installerDefaults.autoSoftwareUpdateEnabled = "yes"
installerDefaults.componentDownloadEnabled = "yes"
installerDefaults.dataCollectionEnabled = "no"
mks.ctlAltDel.ignore = "TRUE"
host.cpukHz = "3000000"
host.noTSC = "TRUE"
ptsc.noTSC = "TRUE"
prefvmx.minVmMemPct = "100"
datastore.name = "local"
defaultVMPath = "E:\DEV_Image"

datastore.localpath = "E:\DEV_Image\"

sched.mem.pshare.enable = "FALSE"
prefvmx.useRecommendedLockedMemSize = "TRUE"
prefvmx.minVmMemPct = "100"
priority.grabbed = "normal"
priority.ungrabbed = "normal"

security.host.ruissl = "FALSE"

mainMem.partialLazySave = "FALSE"
mainMem.partialLazyRestore = "FALSE"
mainMem.useNamedFile = "FALSE"

Isolation.tools.copy.enable = "true"
Isolation.tools.paste.enable = "true"
Isolation.tools.HGFS.disable = "false"

What these settings mean and what they are for you can look up  here
http://sanbarrow.com/vmx/vmx-config-ini.html

Thursday, April 14, 2011

Sharepoint 2010 Rename Assembly of WebPart

I came across of a new issue in SharePoint 2010 today. My client wished the web parts assembly name changed from some name A to some name B.
Well I thought easy, rebuild the web part, verify that the web part file is correct, retract old solution, deploy new solution (Web part is deployed as feature).
Well... When I inserted the web part with the new name everything worked. but all the pages that had the web part already inserted stopped working, saying that the type was not found.
The old web parts where trying to load the old assembly.
After looking and "googling" I didn't find any solution.. So my last resource... change the entry on the Content DB.  Here is the script

UPDATE
[SiteCollection_Content_DB].[dbo].[AllWebParts]SET [tp_WebPartTypeId] ='NewWebPartTypeId',[tp_Assembly] = 'NewAssemblyBaseNamespace, Version=NewVersion, Culture=neutral, PublicKeyToken=newtoken',[tp_Class] = 'NewCompleteClassNameWithNamespace'
[tp_Class]
WHERE [tp_Assembly] = 'OldAssemblyBaseNamespace, Version=OldVersion, Culture=neutral, PublicKeyToken=oldtoken' and = 'OldCompleteClassNameWithNamespace' and[tp_WebPartTypeId] ='OldWebPartTypeId'
To  know the new values I just inserted one web part with the new dll and copied the values form the record I found on the AllWebParts table .


I strongly recommend though to make a backup of your DB!
I actually never touch the DB of SharePoint. I even convinced my client not to change the Assembly name... But still I tried the script in my Dev environment and it seemed to work.




UPDATE: Wow.. why do it the Unsupported way!... there is the supported way: Open your webApplication, loop through all of your sites & webs. Open each page, check if the webpart's in it, if so get the position(s) of the current web part(s). remove it (them) and insert the new webpart(s) with the new definition in the position(s) fetched.
 

Monday, April 11, 2011

Powershell Script to insert large amount of ListItems in Sharepoint List

A small script I wrote to insert a large amount of items in a custom list. It is just for testing purposes, so I can learn a little bit more about optimizing SPQueries and about ListView thresholds.

if((Get-PSSnapin -Name Microsoft.Sharepoint.PowerShell -ErrorAction SilentlyContinue) -eq $null)
{
 Add-PSSnapin Microsoft.Sharepoint.PowerShell
}
clear
#Get-Command  -Module Microsoft.Sharepoint.PowerShell
$assignment = Start-SPAssignment
$webUrl="http://myweburl/"
$listName = "OneMillionRecords"
$spWeb = Get-SPWeb -Identity $webUrl -AssignmentCollection $assignment
$template = $spWeb.ListTemplates["Custom List"] 
$listId=$spWeb.Lists.Add($listName,"List with one million records",$template)
$spNewList = $spWeb.Lists[$listName]
$spFieldTypeText = [Microsoft.SharePoint.SPFieldType]::Note
$spFieldTypeNumber = [Microsoft.SharePoint.SPFieldType]::Number
$spNewList.Fields.Add(“Description”,$spFieldTypeText,$false)
$spNewList.Fields.Add(“ItemNr”,$spFieldTypeNumber,$false)
$i =1
$max = 1000000
while ($i -le $max) {
$j=$i.ToString()
$title="Item $j"
$itemNr=$i
$description="The Item is called Item $j and is stored with some useless text"
$newItem=$spNewList.items.Add() 
$newItem["Title"] = $title
$newItem["ItemNr"] = $itemNr
$newItem["Description"]=$description
$newitem.Update()
Write-Host $title
$i=$i+1
}
#Dispose all objects
Stop-SPAssignment $assignment

Saturday, April 9, 2011

PowerShell: Create Users in active directory and Sharpoint 2010

Small powerschell script that creates an amount of users in the Active Directory and inserts them in the Sharepoint 2010

Import-Module ActiveDirectory
if((Get-PSSnapin -Name Microsoft.Sharepoint.PowerShell -ErrorAction SilentlyContinue) -eq $null)
{
 Add-PSSnapin Microsoft.Sharepoint.PowerShell
}
#Get-Command -Module ActiveDirectory
clear
$i =3
while ($i -le 100000) {
$j=$i.ToString()
$username="Dev$j"
$webUrl="http://sharepoint website url/"
$group="Development Owners"

New-ADUser -SamAccountName $username -Name $username -UserPrincipalName "$username@domain.com" -DisplayName "$username User" -GivenName $username -Surname "User" -AccountPassword (ConvertTo-SecureString -AsPlainText "pass@word1" -Force) -Enabled $true -PasswordNeverExpires $false -Path 'CN=Users,DC=Domain,DC=com'

New-SPUser -UserAlias "Domain\$username" -Web $webUrl -DisplayName "$username User" -Group $group

Set-SPUser -Identity "Domain\$username" -Web $webUrl  -SyncFromAD:$true
$i=$i+1
}