If you're using the JAMS Snapin for PowerShell you've already found that every cmdlet has a "-Server" parameter that you can use to specify which JAMS Server should be used. However, you probably don't want to use it! The -Server parameter is fine when you want to explicitly specify the JAMS Server but it's easier to use one of the defaults.
Here's how a JAMS cmdlet determines which JAMS Server it should use:
- Was -Server specified on the command line?
- Is the $JAMSDefaultServer PowerShell variable defined?
- Is our current default location a JAMS Provider drive?
- Are we being executed as batch job by a JAMS Server?
- Pick the first first JAMS Provider drive.
- Throw an exception.
Setting $JAMSDefaultServer is what we usually use when working interactively. You might want to set that in your PowerShell profile but, be careful or you'll break option 4. Option 4, checking to see if the cmdlet is being executed as a JAMS job, may be the most interesting option. The idea is to make it easy to use JAMS cmdlets in your jobs without requiring any changes when the job moves from a test server to a production server.
So, how can you set $JAMSDefaultServer in your profile without breaking the default host option? Simple, just check for the $Host.PrivateData. When JAMS executes a job, it creates a HostName property in $Host.PrivateData so you can do this in your profile:
if ($Host.PrivateData.HostName -eq $null)
{
$JAMSDefaultServer = "MyJAMSServer"
}