Import-PSSession : Proxy creation has been skipped for '%' command, because PowerShell couldn't verify its name as safe

26,562

Solution 1

I resolved this by simply entering the remote session instead of importing it. I was then able to add the SharePoint snap-in installed on the remote machine and run my script.

$Session = New-PSSession -ConfigurationName "Microsoft.PowerShell" -ConnectionUri "http://app01-spl1:5985/wsman/" -Authentication "Kerberos" 
Enter-PSSession $Session
Add-PSSnapin Microsoft.SharePoint.PowerShell

<Cmdlets or script goes here>

Exit-PSSession
Remove-PSSession -ID $Session.ID
[GC]::Collect()

Another option is to use Invoke-Command cmdlet with the ScriptBlock parameter like so.

$Session = New-PSSession -ConfigurationName Microsoft.PowerShell -ConnectionUri "http://app01-spl1:5985/wsman/" -Authentication Kerberos
Invoke-Command -Session $Session -ScriptBlock { Add-PSSnapin Microsoft.SharePoint.PowerShell }

Invoke-Command -Session $Session -ScriptBlock { <Your cmdlet here.> }

Remove-PSSession -ID $Session.ID
[GC]::Collect()

Solution 2

The error is that you are trying to import the entire set of commands from your remote server. Not quite sure why you are allowing clobber.

Personally, I'd just import the relevant SHarePoint module(s) rather than all of the remote workspace.

Does the import work??

Share:
26,562
Nicholas J. Markkula
Author by

Nicholas J. Markkula

Updated on August 07, 2020

Comments

  • Nicholas J. Markkula
    Nicholas J. Markkula over 3 years

    I have a Sharepoint farm setup and I'm connecting to one of my application/search servers from a Windows 7 machine in the domain using remote powershell. Both the client and application servers have powershell 2 with the execution policy set to unrestricted and psremoting enabled. Additionally, i'm running the cmdlets as a domain administrator account.

    I can create a session to the remote server using the following cmdlets:

    $Session = New-PSSession -ConfigurationName "Microsoft.PowerShell" -ConnectionUri "http://app01-spl1:5985/wsman/" -Authentication "Kerberos" 
    Import-PSSession $Session -AllowClobber
    

    However, When I Import the session I get the following eror:

    Import-PSSession : Proxy creation has been skipped for '%' command, because PowerShell couldn't verify its name as safe.
    At line:1 char:17
    + Import-PSSession <<<<  $Session -AllowClobber
        + CategoryInfo          : InvalidData: (:) [Import-PSSession], InvalidOperationException
        + FullyQualifiedErrorId : ErrorSkippedUnsafeCommandName,Microsoft.PowerShell.Commands.ImportPSSessionCommand
    Import-PSSession : Proxy creation has been skipped for '?' command, because PowerShell couldn't verify its name as safe.
    At line:1 char:17
    + Import-PSSession <<<<  $Session -AllowClobber
        + CategoryInfo          : InvalidData: (:) [Import-PSSession], InvalidOperationException
        + FullyQualifiedErrorId : ErrorSkippedUnsafeCommandName,Microsoft.PowerShell.Commands.ImportPSSessionCommand
    Import-PSSession : Could not resolve remote alias 'ise'.
    At line:1 char:17
    + Import-PSSession <<<<  $Session -AllowClobber
        + CategoryInfo          : OperationTimeout: (:) [Import-PSSession], ArgumentException
        + FullyQualifiedErrorId : ErrorCouldntResolveAlias,Microsoft.PowerShell.Commands.ImportPSSessionCommand
    

    Can anyone help solve this error?

  • Nicholas J. Markkula
    Nicholas J. Markkula over 11 years
    You're right about allow clobber, the option is not needed since I don't have any commands in my local session that would conflict with the remote session. However, I'm not able to import the SharePoint modules until I've established the remote connection since they are not installed on my local machine.
  • Thomas Lee
    Thomas Lee over 11 years
    when you import a session (with clobber), then every cmdlet in the remote session is replaced by a local 'proxy' function. Thus 'get-help' on your local machine would be replaced by a similary named function that ran remotely. Thus running get-help locally ends up runnign get-help remotely. The trick is, imho, NOT clobber locally. In general, I suggest you only import specific modules from the remote session.
  • Danijel-James W
    Danijel-James W almost 6 years
    What is [GC]::Collect() ?
  • Nicholas J. Markkula
    Nicholas J. Markkula almost 6 years
  • jacobappleton
    jacobappleton over 5 years
    This doesn't identify why the error occurred in the first place and how to mitigate it, but is rather a work-around. Does anyone know if there is a way to mitigate this issue?
  • Nicholas J. Markkula
    Nicholas J. Markkula over 5 years
    @jacobappleton As far as I understand it, the problem occurs because proxy functions are created for every cmdlet in the remote session when the session is imported. Unfortunately, proxies can't be created for all of the remote cmdlets, some of them are aliases like % for example starts a script block, for whatever reason Powershell can't verify it's name as safe. The workaround should work in most case though, it has the same result as importing the session, either way the cmdlets are executed remotely.