header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
No snap-ins have been registered for Windows PowerShell version 2
Last Post 13 Sep 2010 08:22 AM by Robert Kirchhof. 13 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
Robert KirchhofUser is Offline
New Member
New Member
Posts:13
Avatar

--
30 Aug 2010 07:05 AM
    I'm using the following code (It takes scripttext and passes it to powershell ) on a 64 Bit system using Visual Studio 2010 Express Basic. The problem I'm encountering is it won't load the Exchange snap-in. I believe it's debugging in 32 Bit, but I don't know how to force it to 64. Any help would be greatly appreciated.

    Private Function RunScript(ByVal scriptText As String) As String

            ' create Powershell runspace         

            Dim rsConfig As RunspaceConfiguration = RunspaceConfiguration.Create()

            Dim snapInException As PSSnapInException = Nothing

            Dim info As PSSnapInInfo

            info = rsConfig.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin", snapInException)

            Dim myRunSpace As Runspace = RunspaceFactory.CreateRunspace(rsConfig)

            myRunSpace.Open()

     

            ' create a pipeline and feed it the script text

            Dim MyPipeline As Pipeline = MyRunSpace.CreatePipeline()

            MyPipeline.Commands.AddScript(scriptText)

            ' add an extra command to transform the script output objects into nicely formatted strings

            ' remove this line to get the actual objects that the script returns. For example, the script

            ' "Get-Process" returns a collection of System.Diagnostics.Process instances.

            MyPipeline.Commands.Add("Out-String")

            ' execute the script

            Dim results As Collection(Of PSObject) = MyPipeline.Invoke()

            ' close the runspace

            MyRunSpace.Close()

            ' convert the script result into a single string

            Dim MyStringBuilder As New StringBuilder()

            For Each obj As PSObject In results

                MyStringBuilder.AppendLine(obj.ToString())

            Next

            ' return the results of the script that has

            ' now been converted to text

            Return MyStringBuilder.ToString()

        End Function

    Marco Shaw (MVP)User is Offline
    Veteran Member
    Veteran Member
    Posts:1647
    Avatar

    --
    30 Aug 2010 06:50 PM
    Not that it may matter, but is this with Exchange 2007 or 2010? I don't do enough VB nor do I have enough time, but wanted to ask you to clarify.
    Marco

    *Microsoft MVP - Windows PowerShell
    https://mvp.support.microsoft.com/profile/Marco.Shaw
    *Co-Author - Sams Windows PowerShell Unleashed 2nd Edition
    *Blog - http://marcoshaw.blogspot.com
    Robert KirchhofUser is Offline
    New Member
    New Member
    Posts:13
    Avatar

    --
    31 Aug 2010 04:59 AM
    It is Exchange 2007. The PowerShell script performs as expected from the Exchange Mgmt. Shell. I optained the info needed to use Exchange Management Shell Commands With Managed Code from here: http://msdn.microsoft.com/en-us/lib...G.80).aspx The programming language shouldn't matter. What I need is to configure Visual Studio 2010 Express to debug / compile to 64 Bit.
    Robert KirchhofUser is Offline
    New Member
    New Member
    Posts:13
    Avatar

    --
    31 Aug 2010 12:44 PM
    I made a great deal of progress today. It seems that VS2010 Express doesn't support 64 bit debugging. "If you debug a 64-bit application on the local computer, Visual Studio uses remote debugging to connect between WOW64 and the 64-bit application on the same computer. For more information, see Debugging on a 64-Bit Platform. The remote debugging components will be installed automatically when you install Visual Studio on the computer." http://msdn.microsoft.com/en-us/lib...84681.aspx but to do this you need remote debugging components and they are not available for Express. http://msdn.microsoft.com/en-us/lib...27f1t.aspx I installed VS2010 Prof. Only to encounter this error next. "Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information" To fix this I had to add an App.config file to my application with (contents of app.config found here) http://msmvps.com/blogs/rfennell/ar...erver.aspx It worked but it took 40 Min to create a mailbox!
    Robert KirchhofUser is Offline
    New Member
    New Member
    Posts:13
    Avatar

    --
    31 Aug 2010 01:00 PM
    When I ran it outside of the test environment it only took a few minutes to create the mailbox. The remote debug monitor was sucking up all of my CPU.
    Marco Shaw (MVP)User is Offline
    Veteran Member
    Veteran Member
    Posts:1647
    Avatar

    --
    31 Aug 2010 05:12 PM
    OK, sorry, where do things currently stand?
    Marco

    *Microsoft MVP - Windows PowerShell
    https://mvp.support.microsoft.com/profile/Marco.Shaw
    *Co-Author - Sams Windows PowerShell Unleashed 2nd Edition
    *Blog - http://marcoshaw.blogspot.com
    Robert KirchhofUser is Offline
    New Member
    New Member
    Posts:13
    Avatar

    --
    01 Sep 2010 04:57 AM
    That's it.
    Sol KestonUser is Offline
    New Member
    New Member
    Posts:4
    Avatar

    --
    04 Sep 2010 06:42 AM
    I am having a similar problem but am not clear on how you got past the first error.  I got it running Visual Studio 2010 Ultimate on Windows 2008 R2 x64.  I have .net 2, 3.5, and 4 installed.  I get the error whether I run the CPU as all types or x64.  I get compiled in both 2.0 and 4.0.  I get it whether I register my dll with installtuil in the x64 flavor or the x86.  The only time I get a different error is when I am set to run as x64 and run in debug mode because I didnt have the remote debugger setup that you mentioned.  Note that I had to download the remote debugger configuration wizard to set it up for ASP .net as it is missing from the Visual Studio install. 
    I have also tried setting everyting up on another server that is Windows 2008 SP2 RTM instead of R2 with the same results.  I get the No snap-ins have been registered for Windows Powershell version 2 on R2 and version 1 on RTM.  My code is basically the same as yours:

        Dim psRunConfig As RunspaceConfiguration
            psRunConfig = RunspaceConfiguration.Create()
            Dim snapInException As PSSnapInException
            Dim info As PSSnapInInfo
            Try
                info = psRunConfig.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin", snapInException)
                Dim psRunSpace As Runspace = RunspaceFactory.CreateRunspace(psRunConfig)
                psRunSpace.Open()
                Dim psPipeline As Pipeline = psRunSpace.CreatePipeline()
                Dim getExchServer As Command = New Command("get-exchangeserver")
                psPipeline.Commands.Add(getExchServer)
               Dim PSOutput As Collection(Of PSObject) = psPipeline.Invoke()
                Return PSOutput
            Catch ex As Exception
                txtFeed.Text = ex.Message
            End Try
    Robert KirchhofUser is Offline
    New Member
    New Member
    Posts:13
    Avatar

    --
    04 Sep 2010 09:05 AM
    If you don't figure it out by monday we'll chat some more. Did you add the App.config file?
    Sol KestonUser is Offline
    New Member
    New Member
    Posts:4
    Avatar

    --
    04 Sep 2010 03:06 PM
    I updated the WebDev.WebServer40.exe.config, are you talking about something else? This is an asp.net app, do you mean web.config? I havent made changes there, is there something needed?
    Robert KirchhofUser is Offline
    New Member
    New Member
    Posts:13
    Avatar

    --
    04 Sep 2010 04:00 PM
    What error are you getting now? is it this one "Mixed mode assembly is built against version 'v2.0.50727' error using .NET 4 Development Web Server" ? If so see this link.

    http://msmvps.com/blogs/rfennell/ar...erver.aspx
    Sol KestonUser is Offline
    New Member
    New Member
    Posts:4
    Avatar

    --
    05 Sep 2010 04:00 AM
    No, I am still getting no snap-ins have been registered for windows powershell
    Sol KestonUser is Offline
    New Member
    New Member
    Posts:4
    Avatar

    --
    13 Sep 2010 07:05 AM
    I am back in town and having the same issue. What do you suggest?
    Robert KirchhofUser is Offline
    New Member
    New Member
    Posts:13
    Avatar

    --
    13 Sep 2010 08:22 AM
    "no snap-ins have been registered for windows PowerShell" is caused by the PowerShell shell running in 32bit instead of 64 bit. I don't know what else I can say. My app was VS Basic and it ran locally. I'm sorry I don't know how to help you further.
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer