Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 在文件路径中使用Scriptblock调用命令-无参数_Powershell_Exchange Server 2016 - Fatal编程技术网

Powershell 在文件路径中使用Scriptblock调用命令-无参数

Powershell 在文件路径中使用Scriptblock调用命令-无参数,powershell,exchange-server-2016,Powershell,Exchange Server 2016,我正在编写PowerShell脚本,以覆盖Exchange 2016上的外出文本 我在运行所有任务的远程服务器上执行此操作 这就是我所说的: Invoke-Command -Session $Session -FilePath $filepath 使用参数-FilePath调用此ps1,它可以工作,它可以用于更简单的文件。 现在转到放入文件路径的文件: Get-Mailbox | Get-MailboxAutoReplyConfiguration | where {$_.AutoRep

我正在编写PowerShell脚本,以覆盖Exchange 2016上的外出文本

我在运行所有任务的远程服务器上执行此操作

这就是我所说的:

Invoke-Command -Session $Session -FilePath $filepath
使用参数
-FilePath
调用此ps1,它可以工作,它可以用于更简单的文件。 现在转到放入文件路径的文件:

Get-Mailbox | Get-MailboxAutoReplyConfiguration |
    where {$_.AutoReplyState -eq "Disabled"} |
    Set-MailboxAutoReplyConfiguration -AutoReplyState Disabled -InternalMessage "ExampleTextIrrelevant"
因此,我得到所有邮箱,然后是配置,只有禁用的邮箱,然后设置新文本

它在ExchangeServer上工作

现在我得到以下错误,他不喜欢我的
where
子句中的变量
$.
,也不喜欢
where
子句中的脚本块

我还尝试用
where Object
等替换
where
,但它不起作用

错误消息(德语):


我找到了解决办法:


在Exchange服务器上的IIS上,编辑Powershell的web.config。在那里,您可以将语言编辑为FullLanguage。

那么您的问题是什么?听起来好像你没有让对象通过你的管道。它在本地工作,但不是远程。错误是:不可能有脚本块和变量(§)…通常最好发布准确的错误消息-这样任何愿意帮助您的人都不必猜测。指定此cmdlet在一台或多台远程计算机上运行的本地脚本。输入脚本的路径和文件名,或通过管道传输脚本路径以调用命令。脚本必须位于本地计算机上或本地计算机可以访问的目录中。使用ArgumentList指定脚本中参数的值。使用此参数时,Windows PowerShell会将指定脚本文件的内容转换为脚本块,将脚本块传输到远程计算机,并在远程计算机上运行。已更新错误信息 In Zeile:1 Zeichen:57 + ... ReplyConfiguration | where {$_.AutoReplyState -eq "Disabled"} | Set-M ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Skriptblockliterale sind im eingeschränkten Sprachmodus oder in einem "Data"-Abschnitt nicht zulässig. In Zeile:1 Zeichen:58 + ... Get-MailboxAutoReplyConfiguration | where {$_.AutoReplyState -eq "Di ... + ~~~~~~~~~~~~~~~~~ Eigenschaftsverweise sind im eingeschränkten Sprachmodus oder in einem "Data"-Abschnitt nicht zulässig. In Zeile:1 Zeichen:58 + Get-Mailbox | Get-MailboxAutoReplyConfiguration | where {$_.AutoReply ... + ~~ Es wird auf eine Variable verwiesen, auf die im eingeschränkten Sprachmodus oder in einem Data-Abschnitt nicht verwiesen werden darf. Zu den Variablen, auf die verwiesen werden darf, gehören folgende: $PSCulture, $PSUICulture, $true, $false, $null. + CategoryInfo : ParserError: (:) [], ParseException + FullyQualifiedErrorId : ScriptBlockNotSupportedInDataSection + PSComputerName : sv-exchange
$User = "domain\user"
$PWord = ConvertTo-SecureString -String "PasWorD" -AsPlainText -Force   
$UserCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord 

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://ExchangeServer/PowerShell/ -Authentication Kerberos -Credential $UserCredential