gpt4 book ai didi

powershell - PowerShell cmdlet参数列表中的if语句

转载 作者:行者123 更新时间:2023-12-03 01:30:11 25 4
gpt4 key购买 nike

Send-Message `
-From $emailAuthUser `
-To $($emailTo -split ',') `
if($emailCC -ne "NA") { -CC $($emailCC -split ',') } `
-Subject $emailSubject `
-Body $emailBody `
-Attachments $attachments `
-ReplyTo $($emailReplyTo -split ',') `
-SmtpServer $emailSmtpServer `
-Port $emailSmtpPort `
-Credential $creds `
-UseSsl

错误:找不到接受参数'if'的位置参数。

是否有一种 简单方式,可以选择在“内置” cmdlet中包含参数,就像我在上面试图完成的那样?如果是这样,怎么办?

最佳答案

飞溅是执行复杂参数传递的首选方法。您可以将参数存储在哈希表中,然后使用IF块将其添加到哈希表中。然后将哈希值撒入您的命令中。

$Params = @{
From = $emailAuthUser;
To = $($emailTo -split ',');
Subject = $emailSubject;
Body = $emailBody;
Attachments = $attachments;
ReplyTo = $($emailReplyTo -split ',');
SmtpServer = $emailSmtpServer;
Port = $emailSmtpPort;
Credential = $creds;
UseSsl = $True;
}

if($emailCC -ne "NA") { $Params['CC'] = ($emailCC -split ',') }

Send-Message @Params

关于powershell - PowerShell cmdlet参数列表中的if语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58997850/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com