Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 762
Nicholas J. Markkula Avatar asked Aug 03 '12 18:08

Nicholas J. Markkula


2 Answers

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()
like image 92
Nicholas J. Markkula Avatar answered Nov 13 '22 19:11

Nicholas J. Markkula


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??

like image 33
Thomas Lee Avatar answered Nov 13 '22 21:11

Thomas Lee