I have been playing with creating my own PSSessionConfiguration in PS V3 on 2008 R2 Enterprise SP1. For the most part I’ve been able to successfully get most aspects working, but I am puzzled when it comes to using a PSSnapin in the ModulesToImport. Standard modules work fine.
According to get-help the -ModulesToImport parameter is String with a default value of Microsoft.PowerShell.Core, and “Specifies the modules and snap-ins that are automatically imported into sessions that use the session configuration.”
I can include a PSSnapin name in the ModulesToImport parameter of New-PSSessionConfigurationFile & I can then do the Register-PSSessionConfiguration using that file. The PSSessionConfiguration looks like this:
PS C:\> Get-PSSessionConfiguration TestSnapinEndPoint | FL *
Copyright : (c) 2014 Don Hunt. All rights reserved.
Description : Trying to find syntax of PSSnapin in ModulesToImport
CompanyName : Unknown
GUID : 4054684b-38ee-4353-ae69-dee49c1dbf7f
Author : Don Hunt
ModulesToImport : {WDeploySnapin3.0, BitsTransfer}
SessionType : Default
ExecutionPolicy : RemoteSigned
SchemaVersion : 1.0.0.0
LanguageMode : FullLanguage
Architecture : 64
Filename : %windir%\system32\pwrshplugin.dll
ResourceUri : http://schemas.microsoft.com/powershell/TestSnapinEndPoint
MaxProcessesPerShell : 15
MaxConcurrentCommandsPerShell : 1000
Capability : {Shell}
xmlns : http://schemas.microsoft.com/wbem/wsman/1/config/PluginConfiguration
MaxConcurrentUsers : 5
pssessionthreadapartmentstate : STA
Name : TestSnapinEndPoint
SupportsOptions : true
pssessionthreadoptions : ReuseThread
ExactMatch : true
ConfigFilePath : C:\Windows\System32\WindowsPowerShell\v1.0\SessionConfig\TestSnapinEndPoint_4054684b-38
ee-4353-ae69-dee49c1dbf7f.pssc
RunAsUser :
IdleTimeoutms : 7200000
OutputBufferingMode : Block
PSVersion : 3.0
SecurityDescriptorSddl : O:NSG:BAD:P(D;;GA;;;NU)(A;;GA;;;BA)S:P(AU;FA;GA;;;WD)(AU;SA;GXGW;;;WD)
MaxShellsPerUser : 25
AutoRestart : false
MaxShells : 25
MaxIdleTimeoutms : 43200000
Uri : http://schemas.microsoft.com/powershell/TestSnapinEndPoint
SDKVersion : 2
XmlRenderingType : text
RunAsPassword :
ProcessIdleTimeoutSec : 0
ParentResourceUri : http://schemas.microsoft.com/powershell/TestSnapinEndPoint
Enabled : True
UseSharedProcess : false
MaxMemoryPerShellMB : 1024
lang : en-US
Permission : NT AUTHORITY\NETWORK AccessDenied, BUILTIN\Administrators AccessAllowed
However, I get a runtime error when I try to use this configuration.
PS C:> $pssnap = New-PSSession -EnableNetworkAccess -ConfigurationName TestSnapinEndPoint
New-PSSession : One or more errors occurred processing the module ‘WDeploySnapin3.0’ specified in the
InitialSessionState object used to create this runspace. See the ErrorRecords property for a complete list of errors.
The first error was: The specified module ‘WDeploySnapin3.0’ was not loaded because no valid module file was found in
any module directory.
At line:1 char:11
- $pssnap = New-PSSession -EnableNetworkAccess -ConfigurationName TestSnapinEndPoi …
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~- CategoryInfo : OpenError: (System.Manageme…RemoteRunspace:RemoteRunspace) [New-PSSession], RemoteExc
eption - FullyQualifiedErrorId : PSSessionOpenFailed
- CategoryInfo : OpenError: (System.Manageme…RemoteRunspace:RemoteRunspace) [New-PSSession], RemoteExc
I have been able to work around this by specifying a ScriptsToProcess entry, which just did an Add-PSSnapin of the needed snap in.
Any insight would be appreciated.
Don