Import-PSSession:已为'%'命令跳过代理创建,因为PowerShell无法验证其名称是否安全

Nic*_*ula 9 powershell powershell-2.0 powershell-remoting

我有一个Sharepoint服务器场设置,我正在使用远程PowerShell从域中的Windows 7计算机连接到我的一个应用程序/搜索服务器.客户端和应用程序服务器都具有PowerShell 2,执行策略设置为不受限制且启用了psremoting.此外,我正在运行cmdlet作为域管理员帐户.

我可以使用以下cmdlet创建到远程服务器的会话:

$Session = New-PSSession -ConfigurationName "Microsoft.PowerShell" -ConnectionUri "http://app01-spl1:5985/wsman/" -Authentication "Kerberos" 
Import-PSSession $Session -AllowClobber
Run Code Online (Sandbox Code Playgroud)

但是,当我导入会话时,我得到以下错误:

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
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮助解决此错误?

Nic*_*ula 7

我通过简单地输入远程会话而不是导入它来解决这个问题.然后,我可以添加安装在远程计算机上的SharePoint管理单元并运行我的脚本.

$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()
Run Code Online (Sandbox Code Playgroud)

另一种选择是将Invoke-Command cmdlet与ScriptBlock参数一起使用.

$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()
Run Code Online (Sandbox Code Playgroud)