IT tutorials
 
Applications Server
 

Sharepoint 2010 : Windows PowerShell Remoting (part 2) - Entering a Remote Session, Running SharePoint 2010 Cmdlets Remotely

11/18/2014 8:20:24 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

Entering a Remote Session

You can start a remote session against the target computer with the Enter-PSSession cmdlet:

PS > Enter-PSSession -ComputerName SPServer01.powershell.nu `
>> -Authentication CredSSP -Credential powershell\administrator

This starts an interactive session with a remote computer using CredSSP authentication. During the session, all commands that you type run on the remote host. You can stop the remote session with the Exit-PSSession cmdlet:

PS > Exit-PSSession

To run commands against multiple remote computers, combine the New-PSSession and Invoke-Command cmdlets. The New-PSSession cmdlet creates persistent connections to remote computers. The Invoke-Command cmdlet runs a script block on the computers specified in the New-PSSession cmdlet. Here’s an example:

PS > $Session = New-PSSession '
>> -ComputerName SPServer01.powershell.nu, Server1.powershell.nu `
>> -Authentication CredSSP -Credential powershell\administrator
PS > Invoke-Command -Session $Session -ScriptBlock {
>> "Running Remote commands on: $($Env:COMPUTERNAME)"
>> $regKey = "hklm:software\microsoft\shared tools\web server extensions\14.0"
>> if(Test-Path -Path $regKey) {
>> if(get-itemProperty -Path $regKey |
>> Where-Object { $_.SharePoint -eq "Installed" }) {
>> "$($Env:COMPUTERNAME) is running SharePoint 2010"
>> } else {
>> "$($Env:COMPUTERNAME) is not running SharePoint 2010"
>> }
>> } else {
>> "$($Env:COMPUTERNAME) is not running SharePoint 2010"
>> }
>> }
>>
Running Remote commands on: SERVER1
SERVER1 is not running SharePoint 2010
Running Remote commands on: SPSERVER01
SPSERVER01 is running SharePoint 2010



In the script block in this example, we check if the remote computer has the registry key HKLM\Software\Microsoft\Shared Tools\Web Server Extensions\14.0 using the Test-Path cmdlet. If the key exists, we check if the SharePoint string value is equal to Installed. Depending on the outcome of condition evaluation, we then output an informational message stating whether SharePoint is installed on that particular server.

Note

Checking the registry for keys and values is a quick and simple way to verify that SharePoint 2010 is installed on the server.


Running SharePoint 2010 Cmdlets Remotely

Windows PowerShell includes the Add-PSSnapin cmdlet, which is used to add registered snap-ins to the current session. After a snap-in is added, you can use cmdlets and providers that the snap-in supports. When SharePoint 2010 is installed, it also installs a Windows PowerShell snap-in for SharePoint. You can use the snap-in to run cmdlets included in SharePoint 2010 remotely.

PS > Enter-PSSession -ComputerName SPServer01.powershell.nu `
>> -Authentication CredSSP -Credential powershell\administrator

[SPServer01.powershell.nu]: PS > Get-PSSnapin -Registered

Name : Microsoft.SharePoint.PowerShell
PSVersion : 1.0
Description : Register all administration Cmdlets for Microsoft SharePoint Server

[SPServer01.powershell.nu]: PS > Add-PSSnapin Microsoft.SharePoint.PowerShell



In this example, we use the Enter-PSSession cmdlet to start an interactive session on the server SPServer01. We then use the Get-PSSnapin cmdlet to retrieve all registered snap-ins. Since the server has SharePoint 2010 installed, Microsoft.SharePoint.PowerShell is returned. We can add the snap-in with the Add-PSSnapin cmdlet and invoke all the cmdlets available in SharePoint 2010 remotely. In a standard remote Session each pipeline, function, or script is run on its own thread. To start a remote session that runs pipelines, functions, and scripts on the same thread, you have to create a custom session configuration on every server in the farm that you want to manage remotely. This example demonstrates how to create a custom session configuration.

PS > Register-PSSessionConfiguration -Name SharePoint -ThreadOptions ReuseThread



When starting a remote session against a server in the farm that contains a custom session configuration, you can simply use the ConfigurationName parameter as demonstrated in this example:

PS > Enter-PSSession -ComputerName SPServer01.powershell.nu `>> -Authentication
CredSSP -Credential powershell\administrator `>> -ConfigurationName SharePoint
 
Others
 
- Sharepoint 2010 : Windows PowerShell Remoting (part 1)
- Sharepoint 2010 : Windows PowerShell Scripts (part 3) - Writing Comment-Based Help Topics in Scripts,Using Functions in Scripts , Customizing Windows PowerShell with Profile Scripts
- Sharepoint 2010 : Windows PowerShell Scripts (part 2) - Executing Scripts, Using Parameters in Scripts
- Sharepoint 2010 : Windows PowerShell Scripts (part 1) - Setting the Execution Policy
- Sharepoint 2010 : Windows PowerShell Functions
- Sharepoint 2013 : Security and Policy - SharePoint Users
- Sharepoint 2013 : Security and Policy - Permissions and Permission Levels (part 2) - Creating Custom Permission Levels
- Sharepoint 2013 : Security and Policy - Permissions and Permission Levels (part 1)
- Sharepoint 2013 : Security and Policy - Security Administration
- Installing Exchange Server 2010 : Command-Line Setup (part 2) - Command-Line Server Recovery Options , Command-Line Delegated Server Installation , Installing Language Packs
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us