Monday, February 22, 2016

Adding DLL to WSP SharePoint 2010

In order to add custom dll to WSP Package , follow these steps:


  • Create new Empty SharePoint Project 
    • File->New->Project->SharePoint(2010)->Empty SharePoint Project 
    • In second screen provide test site URL
    • Select "Deploy as Farm Solution"

  • Expand package node and double click on Package.package file 




  • Click on "Advanced" Tab



  • Add the Custom dll's using the "Add" button



  • Save the project, compile and deploy. Custom dll will be part of WSP.

Tuesday, August 28, 2012

Changing PowerShell script execution settings

If you administer servers on a domain and use Powershell, you might come across this error:

File C:\<your file>.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.

Step 1. View the current execution settings

PS C:\> Get-ExecutionPolicy <hit Enter>

It may return "Restricted" which will prevent you from executing any scripts at all...even those written by you.

Step 2. Set the execution setting

PS C:\> Set-ExecutionPolicy RemoteSigned

This will allow you to run only signed scripts and those written by you...provided you have the proper permissions to do so.


Tuesday, August 14, 2012

How To Restart Computers Remotely via PowerShell

It is a fact that Windows administrators periodically need to reboot servers and desktops. Because of this fact, I always was running into scripts that would remotely reboot a group of computers. But in PowerShell, this is now (dangerously) easy and no scripting is required. All we need is the Restart-Computer cmdlet.
You can use the cmdlet to restart your own computer without much hassle:

PS C:\> Restart-Computer

To restart a remote computer, you need to run the command with credentials that have the right privileges to remotely shut down a computer, typically an admin account. Assuming my current credentials were adequate, I could easily reboot the computer SERVER01:

PS C:\> Restart-Computer Server01 -whatif

What if: Performing operation "Restart-Computer" on Target " (Server01)".

although I didn't really; I took advantage of the -WhatIf parameter to verify my command. This is especially helpful if I'm rebooting a bunch of servers:

PS C:\> restart-computer "server01","server02","server03" -whatif

By the way, here's how you could shut down a list of computers:

PS C:\> restart-computer (get-content c:\work\computers.txt)

Because the cmdlet is using WMI objects and methods under the hood you can specify alternate credentials, either a saved credential object or a user name:

PS C:\> restart-computer (get-content c:\work\computers.txt) -credential "mycompany\administrator"

I'll get prompted for the password, but then this credential will be used for every computer in the list.

The Restart-Computer cmdlet will fail, if a logon session is detected. PowerShell will raise an exception. However, you can force a reboot using -- what else? -- the -force parameter. Be aware this will force applications to close with the potential loss of unsaved work.

Another option for rebooting or even logging off is to use the Win32_OperatingSystem WMI Class and the Win32ShutDown method. I recommend using Invoke-WMIMethod because it supports -WhatIf and -Confirm. I found it just as easy to pipe a WMI object from Get-WMIObject to Invoke-WMIMethod:

PS C:\> Get-WmiObject win32_operatingsystem -ComputerName Quark | Invoke-WMIMethod -name Win32Shutdown

The Win32Shutdown method can accept parameters. The default is 0 which means do a simple logoff. But if the user has open files or if the default method fails, you can always resort to a forceful logoff:

PS C:\> Get-WmiObject win32_operatingsystem -ComputerName Quark | Invoke-WMIMethod -name Win32Shutdown -ArgumentList @(4)

You have to specify the value for -ArgumentList as an explicit array. If you look at the MSDN documentation for this method you'll discover other method parameter values, which you can certainly use. But personally many of them are duplicated with cmdlets like Restart-Computer and Stop-Computer; given a choice I prefer to use a cmdlet.

I hope it goes without saying that this is pretty powerful ju-ju so be sure you've tested your scripts and tried out these commands in a non-production environment.

jQuery to override SharePoint OOTB Upload.aspx default for "Add as a new version to existing files" checkbox

A common query from SharePoint users with versioning enabled on document libraries is to default the "Add as a new version to existing files" checkbox on the OOTB upload.aspx page to unchecked. If you google how to uncheck it by default you'll get lots of entries showing you how to simply edit the Upload.aspx file in the \TEMPLATE\LAYOUTS\ folder in the 12/14 hive. This works fine of course if you don't care about tomorrow and having a supported/upgradeable SharePoint installation.

If you do there is a better way as described by Per Jakobsen here.
Using the AdditionalPageHead delegate control to inject javascript to the page through a feature not only gives you a supportable system but allows you to switch the default to checked or not checked by activating or deactivating the feature.

I tried a variation of this on a SharePoint 2007 installation and it worked fine, after an upgrade to 2010 it stopped working however. Having spent five minutes trying to debug the issue I decided it would be swifter to just change it to use jQuery's $(document).ready function rather than solve the specific problem. There seems to be others having weird things going on with _spBodyOnLoadFunctionNames.push in 2010, so this is probably a quicker fix (at least if you've already got jQuery available on the page). If you don't you could add a reference to it in the DefaultUploadOverwriteOff.ascx user control.

The change to Jakobsen's javascript is simple, just replace the function DefaultUploadOverwriteOff() with this:

?
1
2
3
4
5
6
$(document).ready(function() {
    if (document.title == "Upload Document") {
        $("input[id$='OverwriteSingle']").attr("checked",false);
        $("input[id$='OverwriteMultiple']").attr("checked",false);
    }
});

and remove the last line: _spBodyOnLoadFunctionNames.push('DefaultUploadOverwriteOff');

This now works fine on both 2007 and 2010.

Adding and Deploying SharePoint 2010 .WSP Solutions

Every SharePoint specialist is doing this process when deploy SP solution package on production server, so I write this article to keep it as a reference for me and share it with others to help and get feedback/ides for best practices.
In my Scenario, I have 2 WSP files:
  • NewSolutionPack.wsp (to add it as first time)
  • UpdateSolutionPack.wsp (to update an exist WSP file)
  • Target web application (http://sps:1)
clip_image001[7]

The steps of deployment are easy:

1. Add solution to Farm Solutions
2. Deploy your solution to a specific web application or to all web applications
3. In case of exists solution, you will upgrade the solution using one of the following options:
a. Retract and delete the old solution, then add and deploy the new one
b. Or, upgrade the existing solution using upgrade method (recommended).

Steps of deployment using STSADM
1. Add solution to Farm Solutions
a. Open cmd (Star > Run > write cmd in box > click ok)
clip_image002[7]
b. Mont the folder that contain stsadm execution file (C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN)
clip_image004[7]
clip_image006[7]
c. Enter the following script
stsadm -o addsolution -filename “C:\WSP Deployment\NewSolutionPack.wsp”
clip_image008[7]
2. Deploy your solution
a. To a specific web application
stsadm -o deploysolution -name “NewSolutionPack.wsp” -url “http://sps:1″ -allowgacdeployment -immediate –allowcaspolicies
clip_image010[7]

Check it from Central Administration > System Settings > Manage Farm Solutions

clip_image012[7]
b. To all web applications
stsadm -o deploysolution -name “NewSolutionPack.wsp” -allcontenturls -allowgacdeployment -immediate –allowcaspolicies

clip_image014[7]
3. Upgrade the solution by Retract and delete the old solution, then add and deploy the new one
a. stsadm -o retractsolution -name “NewSolutionPack.wsp” -url “http://sps:1″ –immediate
if you want to retract the solution from all web applications, you need to use this
stsadm -o retractsolution -name “NewSolutionPack.wsp” -allcontenturls –immediate
b. stsadm -o deletesolution -name “NewSolutionPack.wsp”
c. stsadm -o addsolution -filename “C:\WSP Deployment\NewSolutionPack.wsp”
d. stsadm -o deploysolution -name “NewSolutionPack.wsp” -allcontenturls -allowgacdeployment -immediate –allowcaspolicies
4. Upgrade the solution by using upgrade method
a. Enter upgrade script
stsadm -o upgradesolution -name “NewSolutionPack.wsp” -filename “C:\WSP Deployment\UpdateSolutionPack.wsp” -allowgacdeployment -immediate –allowcaspolicies
clip_image016[7]

Steps of deployment using PowerShell
1. Add solution to Farm Solutions
a. Open PowerShell (SharePoint 2010 Management Shell)
clip_image018[7]
b. Enter the following script:
Add-SPSolution “C:\WSP Deployment\NewSolutionPack.wsp”
clip_image020[7]
2. Deploy your solution
a. To a specific web application
Install-SPSolution -Identity “NewSolutionPack.wsp” -WebApplication “http://sps:1″ -GACDeployment -CASPolicies -Confirm:$false
b. To all web applications
Install-SPSolution -Identity “NewSolutionPack.wsp” -AllWebApplications -GACDeployment -CASPolicies -Confirm:$false
3. Upgrade the solution by Retract and delete the old solution, then add and deploy the new one
a. Uninstall-SPSolution -Identity “NewSolutionPack.wsp” -WebApplication “http://sps:1″ -Confirm:$false
if you want to retract the solution from all web applications, you need to use this
Uninstall-SPSolution -Identity “NewSolutionPack.wsp” -AllWebApplications -Confirm:$false
b. Remove-SPSolution -Identity “NewSolutionPack.wsp” -Confirm:$false
c. Add-SPSolution “C:\WSP Deployment\NewSolutionPack.wsp”
d. Install-SPSolution -Identity “NewSolutionPack.wsp” -WebApplication “http://sps:1″ -GACDeployment -CASPolicies -Confirm:$false
4. Upgrade the solution by using upgrade method:
Update-SPSolution -Identity “NewSolutionPack.wsp” -LiteralPath “C:\WSP Deployment\NewSolutionPack.wsp” -GacDeployment -CASPolicies -Confirm:$false
For more information about mapping from stsadm to PowerShell, read the full MSDN topic: Stsadm to Windows PowerShell mapping (SharePoint Foundation 2010)
I Hope this useful for you,
Thanks.

Friday, November 18, 2011

Generate CSR: IIS 6 Microsoft Windows Server 2003

Follow these instructions to generate a Private Key and CSR. You must have at least Service Pack 1 installed.
  1. Open the Internet Information Services (IIS) Manager. From the Start button select Programs > Administrative Tools > Internet Information Services Manager.
  2. In IIS Manager, double-click the local computer, and then double-click the Web Sites folder.
  3. Right-click the Web site for which you want to request a certificate, and then click Properties. By default it will be Default Web Site, yours may be different.

    Select Default Web Site
  4. Select the Directory Security tab and click Server Certificate in the Secure communications section.
  5. Click Next in the Welcome to the Web Server Certificate Wizard window.
  6. Select Create a new certificate, Click Next.
  7. Select Prepare the request now, but send it later.
  8. At the Name and Security Settings screen, fill in the friendly name field for the new certificate
    Tip: the friendly name can be any name that helps you remember what this certificate is for when you see it in a list later. We recommend using your domain as the friendly name, such as mysite.com.
  9. Select bit length. We recommend using a 2048-bit length (2048 is required for EV SSL). Click Next.
  10. Leave the 'Select cryptographic service provider (CSP) for this certificate' unchecked. Click Next.
  11. You will be asked for several pieces of info which will be used by GeoTrust to create your new SSL certificate. These fields include the Common Name (aka domain, FQDN), organization, country, key bit length, etc. Use the CSR Legend in the right-hand column of this page to guide you when asked for this information. The following characters should not be used when typing in your CSR input: < > ~ ! @ # $ % ^ / \ ( ) ? , &
  12. Enter your Organization (e.g., Gotham Books Inc) and Organizational Unit (e.g., Internet Sales). Click Next.
  13. THIS IS THE MOST IMPORTANT STEP! Enter your site's Common Name. The Common Name is the fully-qualified-domain name for your web site or mail server. What ever your end-user will see in their browser's address bar is what you should put in here. Do not include http:// nor https://. Refer to the CSR legend in the right-hand column of this page for examples. If this is wrong, your certificate will not work properly. Click Next.
  14. Enter your Geographical Information for Country, State, and City. Do not abbreviate States and Cities. Click Next.
  15. In the Certificate Request File Name box enter the path and file name where you want to save your CSR. You can use the default of c:\certreq.txt. Remember where you save it, you'll need to be able to find this CSR file later. Click Next.
  16. Review the data on the Request File Summary screen and click Next.
  17. Click Finish to complete the Wizard.
  18. Now, from a simple text editor such as Notepad (do not use Word), open the CSR file you just created at c:\certreq.txt (your path/filename may be different). You will need to copy-and-paste the contents of this file, including the top and bottom lines, into the relevant box during the online order process.

    Open CSR in Notepad

How To Renew or Create New Certificate Signing Request While Another Certificate Is Currently Installed

Reference MS KB: http://support.microsoft.com/kb/295281

To create a new CSR or generate a renewal request while another certificate exists on your Web site, follow these steps:
  1. In the Microsoft Management Console (MMC), right-click the default Web site, click New, and then click Site.
  2. Create a new site and give it a temporary name.
  3. Right-click the new site, click Properties, click the Directory Security tab, and then click Server certificate.
  4. Select Create new certificate and follow the wizard to create a new CSR. When prompted, select Prepare the request now but send it later.
  5. Use the CSR that you just created to request a new certificate from the certificate authority (CA) that issued the original certificate.

    NOTE: If you are renewing a VeriSign certificate, see the following Web site:
    http://www.verisign.com/repository/digidren.html (http://www.verisign.com/repository/digidren.html)
    If you are unable to renew the certificate by using this Web site, you can reach VeriSign's renewal department at the following e-mail address or telephone numbers:

    E-mail: renewal@verisign.com
    Technical Support: (877) 438-8776
    Sales: (650) 429-3347
  6. When you receive the certificate from VeriSign or another third-party CA, save it to your hard drive. Remember the serial number of this certificate and where you save it.
  7. Right-click the temporary site that you created in step 2, click Properties, click the Directory Security tab, click Server certificate, and then click Next. Follow the wizard. When prompted, select Process the pending request.
  8. After the certificate has been installed, click OK, and then stop and start the Web site.
  9. Right-click the temporary site that you created in step 2, click Properties, click Directory Security, and then click Server certificate.
  10. Select Remove the current certificate and follow the wizard. This removes the certificate from IIS, but the certificate remains in the certificate store.
  11. Right-click the Web site that has the original server certificate installed (that is, the certificate that you are renewing or replacing), click Properties, click Directory Security, click Server certificate, and then select Replace the current certificate.
  12. Select the certificate that you just installed. If you see duplicate certificate names, make sure that you select the certificate that matches the serial number that you noted in step 6.
NOTE: The list of available certificates is populated from the personal certificate store, which is located under Certificates (Local Computer) in the MMC. To view the personal certificate store, add the Certificates snap-in for the Computer Account to your MMC.

NOTE: If IIS does not display the new certificate, you may need to copy it from the personal certificate store that is located under Certificates - Current User in the MMC into the personal certificate store that is located under Certificates (Local Computer). To view the personal certificate store, add the Certificates snap-in for the User Account to your MMC.