Wednesday, August 20, 2014

Adding Windows PowerShell Cmdlets

 You may all have seen some error like below when running a command on Windows PowerShell. This usually occurs when the command PowerShell snap-in is not added.

The term 'Get-SPWebApplication' is not recognized as the name of a cmdlet, function, script file, or operable program.

Solution:  How to add the required snap-in if not already added from the PowerShell script itself.


# Example to add SharePoint Cmdlets [ SharePoint should be installed on machine ]
if ( (Get-PSSnapin -Name Microsoft.Sharepoint.Powershell -ErrorAction SilentlyContinue) -eq $null )
{
    Add-PsSnapin Microsoft.Sharepoint.Powershell
    Write-Output "`n Snap-in Microsoft.SharePoint.PowerShell added."
}
else
{
    Write-Output "`n Snap-in Microsoft.SharePoint.PowerShell already added."
# Example to add SQL Cmdlets [ SQL management tools should be installed on machine ]
if ( (Get-PSSnapin -Name SqlServerCmdletSnapin100 -ErrorAction SilentlyContinue) -eq $null )
{
    Add-PsSnapin SqlServerCmdletSnapin100
    Write-Output "`n Snap-in SqlServerCmdletSnapin100 added."
}
else
{
    Write-Output "`n Snap-in SqlServerCmdletSnapin100 already added."
}
if ( (Get-PSSnapin -Name SqlServerProviderSnapin100 -ErrorAction SilentlyContinue) -eq $null )
{
    Add-PsSnapin SqlServerProviderSnapin100
    Write-Output "`n Snap-in SqlServerProviderSnapin100."
}
else
{
    Write-Output "`n Snap-in SqlServerProviderSnapin100 already added."
}

2 comments:

Travis Smith said...


I know this if off topic but I'm looking into starting my own weblog and was wondering what all is required to get set up? I'm assuming having a blog like yours would cost a pretty penny? I'm not very web savvy so I'm not 100% certain. Any tips or advice would be greatly appreciated. Thank you craigslist albany

Felix Frick said...


Howdy terrific blog! Does running a blog such as this require a large amount of work? I've very little knowledge of coding but I was hoping to start my own blog in the near future. Anyway, should you have any recommendations or tips for new blog owners please share. I understand this is off topic however I simply had to ask. Thanks! all of craigslist

AWS Certified Solutions Architect Associate - AWS Introduction - Questions

All the Best !!! Show Result !! Try Again !! ×