Month: February 2010

PowerShell 2.0 remoting guide: Part 8 – remoting scenarios and troubleshooting

I’ve published a free book on PowerShell 2.0 remoting. You can download it at: [download id=”22″ format=”4″] If you have been following this remoting series and using PS remoting on a test setup or even production, you must have gone through a few initial hiccups. In fact, there could be many such issues if you are working in a mixed environment where you have a few computers in a domain and a few in workgroup. So, in this part of the remoting series I will discuss some of these issues and workarounds to resolve the same. I discussed enabling remoting on workgroup computers in part3 – “Enable remoting” of this series. This post is kind of an extension to that. A more detailed guide is available at about_remote_troubleshooting page on TechNet. I will list only the scenarios I have tested. Remoting to a computer in workgroup from a computer in domain Take an example of two computers, Win7-VM in a domain environment and WinXP-VM in a workgroup. Now, if you want to start a remoting session from Win7-VM using Enter-PSSession …

PowerShell 2.0 remoting guide: Part 7 – saving remote session to disk

I’ve published a free book on PowerShell 2.0 remoting. You can download it at: [download id=”22″ format=”4″] In part 6 of the remoting series we looked at how we can use Import-PSSession cmdlet to execute remote commands as if they were local. This is nice but this will last only while the session ($s in the example) is alive. The moment we kill the session — using Rem0ve-PSSession, remoting session will also get killed. In this part of the series, we will look at how we can save a remoting session to disk so that we don’t even have to explicitly create a session. This is achieved using Export-PSSession cmdlet. This cmdlet lets us import commands from a remote session and save the same in a PowerShell module on the local disk. This cmdlet can get cmdlets, functions, aliases, and other command types in to a PowerShell module. The following example shows how we can achieve this.

In the above example, the first two lines should be quite familiar by now. The third line is where the magic happens. We …

PowerShell 2.0 remoting guide: Part 6 – implicit remoting sessions

I’ve published a free book on PowerShell 2.0 remoting. You can download it at: [download id=”22″ format=”4″] In an earlier post on interactive remoting sessions, we looked at how we can enter a remote session and then execute commands as if they were local. However, if you’d observed it more closely, we were actually sitting in the remote session than local console. The change in PowerShell prompt indicates this fact clearly. In this part of the remoting series, we will look at a feature called implicit remoting which makes it possible to run the commands / scripts on the remote computer while in the local session. We use interactive remoting to overcome a few disadvantages of using Invoke-Command. This method too has its own drawbacks. Within interactive remoting, you explicitly enter/exit a remote session. This also means that you are connected only to one remote computer and you have access only to the cmdlets or modules available on that remote computer. What if you want to access different cmdlets available on different computers? For example, …

PowerShell 2.0 remoting guide: Part 5 – interactive remoting sessions

I’ve published a free book on PowerShell 2.0 remoting. You can download it at: [download id=”22″ format=”4″] In this part of the remoting series, I will talk about using Enter-PSSession and Exit-PSSession cmdlets to perform interactive remoting. Why do you need interactive remoting? To understand the advantages of interactive remoting in PowerShell 2.0, let us first look at some gotchas with Invoke-Command. Take an example of a remote system where SharePoint 2010 is installed. SharePoint 2010 provides native PowerShell cmdlets and these cmdlets can be accesses only if you load Microsoft.SharePoint.PowerShell PS snap-in. So, to do this using Invoke-Command

If you look at the above code, we will have to use a persistent session so that we can use SharePoint cmdlets in subsequent Invoke-Command calls. Another caveat will be the unavailability of remote computer cmdlets in the local PowerShell session — in this case, the SharePoint 2010 cmdlets. This — essentially – means that we cannot use Get-Help or Get-Command cmdlets against the SharePoint 2010 cmdlets in the local session unless we pass that …

PowerShell 2.0 remoting guide: Part 4 – Execute commands or scripts on a remote computer using Invoke-Command

I’ve published a free book on PowerShell 2.0 remoting. You can download it at: [download id=”22″ format=”4″] In this part of PowerShell remoting series, I will discuss how to run commands or scripts on remote computer(s). Within remoting, there are couple of ways to run commands or scripts on a remote machine. This includes Invoke-Command cmdlet and interactive remoting sessions. These two methods deserve a separate post for each and hence I will discuss the Invoke-Command method in today’s post. Once you have enabled remoting on all your computers, you can use Invoke-Command cmdlet to run commands and scripts on local computer or on remote computer(s). There are many possible variations of this cmdlet. I will cover most of them here. Invoke-Command to run commands on local or remote computer You can invoke a command on local or remote computer(s) using the below method

The ScriptBlock parameter can be used to specify a list of commands you want to run on the remote computer.  ComputerName parameter is not required for running commands on the …