Import-session prefixes not working

This topic contains 4 replies, has 3 voices, and was last updated by  Jason Helmick 5 days, 9 hours ago.

  • Author
    Posts
  • #82030

    Coby Carter
    Participant

    Hello!

    I'm trying to test out some remote commands on a server and it's not letting me import the commands to the current session, even when I use a prefix.

    The code I'm currently using is shown below:

    $session = new-pssession -computername server01
    import-pssession -session $session -prefix remote
    

    This runs for about 2 or 3 seconds, and then starts spitting out a bunch of errors all in a row that all say the same thing:

    import-pssession : Proxy creation has been skipped for the '%' command, because Windows PowerShell could not 
    verify the safety of the command name.
    

    There are probably around 25 of the same thing popping up in red text like this. Then, it finishes, and when I run the -verbose command, it says it skipped proxy creation of almost every command.

    What is going on? I'm running it with a prefix, so it shouldn't be clashing. I shouldn't need to use the clobber parameter because it shouldn't be rewriting the computer commands. So why isn't it importing?

    Thank you for your help.

  • #82031

    Don Jones
    Keymaster

    I don't think I've ever tried important all several-hundred default commands from a remote session. You usually only import a module's worth. Can I ask what the use case is? Re-importing a remote Where-Object, for example, doesn't seem to have a lot of value...?

    • #82033

      Coby Carter
      Participant

      I essentially want to be able to use every command for that particular server from my current powershell session.

      I'm mostly curious as to how this works, because I was recently at a conference where Jason Helmick did it himself. He was able to import an entire powershell session with the prefix "Jason". He didn't specify a module. I wanted to see how that would work, so when I attempted it myself, I got these errors.

      When you say you only import a module's worth, what exactly do you mean, and how would I do that?

      Thanks for your reply!

  • #82034

    Don Jones
    Keymaster

    Yeah, that'll not work pretty spectacularly. Your machine would be serialism get and deserializing too much. If that's your goal, just use Invoke-Command. I'll tell Jason to stop showing people that because it's dumb. You're asking your computer to create literally thousands of proxy commands locally, many of which – as you're seeing – it can't determine the safety of.

    You'd specify a module using -Module on Import-Session.

  • #82057

    Jason Helmick
    Keymaster

    Hi Coby! In my demonstration I used the -module parameter and imported the ActiveDirectory Module. I just want to be clear I didn;t import everything from the remote machine, just the specific modules I needed. So choose a couple of modules you want and specifics them with -Module. Normally, I import one, then run the import line again to import another.

    Hope that helps!

    Cheers!

You must be logged in to reply to this topic.