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

Nicholas J. Markkula picture Nicholas J. Markkula · Aug 3, 2012 · Viewed 24.8k times · Source

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?

Answer

Nicholas J. Markkula picture Nicholas J. Markkula · Aug 6, 2012

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()