我似乎在powershell中的mailmessage中收到位置参数错误(144)

我似乎在powershell中的mailmessage中收到位置参数错误(144),powershell,email,automation,mailmessage,Powershell,Email,Automation,Mailmessage,下面是我负责设置的一个内部工具的代码。它基本上引用基于已知值的电子表格,并使用其中一些信息进行排序,并使用其他信息填充自动电子邮件。我已经有好几个版本可以使用了,但不管出于什么原因,它看起来好像其中一个变量没有填充,或者不再接受字符串作为有效的数据类型。我对stack exchange相当陌生,因此如果有任何格式或任何我可以做的事情来澄清问题所在,我很乐意帮忙 echo off #hiding my stuff $Setup = Test-Path "$env:APPDATA\ExcelLoca

下面是我负责设置的一个内部工具的代码。它基本上引用基于已知值的电子表格,并使用其中一些信息进行排序,并使用其他信息填充自动电子邮件。我已经有好几个版本可以使用了,但不管出于什么原因,它看起来好像其中一个变量没有填充,或者不再接受字符串作为有效的数据类型。我对stack exchange相当陌生,因此如果有任何格式或任何我可以做的事情来澄清问题所在,我很乐意帮忙

echo off #hiding my stuff
$Setup = Test-Path "$env:APPDATA\ExcelLocation.txt"
Function Get-FileName($initialDirectory)
{
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null

$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.initialDirectory = $initialDirectory
$OpenFileDialog.filter = "XLSX (*.xlsx)| *.xlsx"
$OpenFileDialog.ShowDialog() | Out-Null
$OpenFileDialog.filename
}

if($Setup -eq $False){
Write-Host "Please participate in 1st time setup!"
$FilePath = Get-FileName "$env:USERPROFILE\Downloads\"
$FilePath | Out-File "$env:APPDATA\ExcelLocation.txt"
$Setup -eq $True
}

$FilePath = Get-Content -Path "$env:APPDATA\ExcelLocation.txt"
Write-Host $FilePath
$DealerCodeLookup = Read-Host -Prompt 'Please put in the Dealer code.'

#Specify the path of the excel file
#$FilePath = "C:\Users\LAB\Downloads\2017 02 Custom Cellular Hierarchy.xlsx"

#Specify the Sheet name
$SheetName = "Sheet1"

# Create an Object Excel.Application using Com interface
$objExcel = New-Object -ComObject Excel.Application
# Disable the 'visible' property so the document won't open in excel
$objExcel.Visible = $false

# Open the Excel file and save it in $WorkBook
$Workbook = $objExcel.Workbooks.Open($FilePath, 2, $True) 
# Load the WorkSheet 'BuildSpecs'
$WorkSheet = $WorkBook.sheets.item($SheetName)
#$WorkBook.sheet | Select-Object -Property Name

  $Row = 1
  $Column = 5
  $Found = $False
  while (($WorkSheet.Cells.Item($Row, $Column).Value() -ne $Null) -and     ($Found -eq $False)) {
                                                                                    #^-- looping though the excel list, updating the row. Stop if Cell is Empty or     Value is Found
If (($WorkSheet.Cells.Item($Row, $Column).Value()).ToUpper() -eq $DealerCodeLookup.ToUpper()) {
                                                                                #^-- Cell value equals $Arg
  $locale = $WorkSheet.Cells.Item($Row, $Column+1).Value() 

  $State =$WorkSheet.Cells.Item($Row, $Column+10).Value()

  $Adrs = $WorkSheet.Cells.Item($Row, $Column+7).Value(),$WorkSheet.Cells.Item($Row, $Column+9).Value(),
  $WorkSheet.Cells.Item($Row, $Column+10).Value(),$WorkSheet.Cells.Item($Row, $Column+11).Value() 
  $Found = $True
}
    $Row += 1                                                                            #Continue to the next row
  }
  Write-Host $State
  $LastRow = $WorkSheet.UsedRange.rows.count + 1
  if($Row = $LastRow -and $Found -eq $False){
  Write-Host "What you put in is not a valid dealer code!"
  $objExcel.quit()
  exit
  }
$objExcel.quit()

#$DealerCode = Read-Host -Prompt 'Please put in the Dealer code.'                     #stores the dealer code
$DealerName = 'CUSTOM CELLULAR'                                                       #Default dealer name (we are custom cellular)
#$Locale = Read-Host -Prompt 'Please put in the Location name.'                       #This stores the human location name
#$Address = Read-Host -Prompt 'Please put in the Location Address.'                   #This stores their address and the thing we use to determine the email address      that is sent.
$SoftTokenAmount = Read-Host -Prompt 'Please put in the amount of tokens needed.' #This stores the amount of tokens needed
$Reason = Read-Host -Prompt 'Why do you have to order these tokens??'             #This stores the reason for our request



#$SoutheastArea = '* MO *','* KS *','* IL *','* WI *','* MN *','* IA *','*     IN *','* NE *' <--possible more efficient usage of the determining loop

#Below is the if statement that determes the     Region(SoutheastArea,CenteralArea,WesternArea)

    #This specific loop is for the SoutheastArea
if($State -like '*MO*' -or ($State -like '*KS*') -or ($State -like '*IL*') -    or ($State -like '*WI*') -or ($State -like '*MN*') -or ($State -like '*IA*')-or      ($State -like '*IN*') -or ($State -like '*NE*'))
    {
        $To = "shalasere1@gmail.com"
    }


    #This loop is for the CentralArea   
Elseif($State -like '*TN*' -or ($State -like '*GA*'))
    {
        $To = "shalasere2@gmail.com"
    }

    #This loop is for the WesternArea
Elseif($State -like '*CO*' -or ($State -like '*UT*'))
    {
        $To = "shalasere3@gmail.com"
    }

$From = "tokenrequest@ccinational.com" #Default from email, mine.
#$Cc = "YourBoss@YourDomain.com"  #Optional CC'd users to said email     (possibly yours.)
$Subject = "Token Request"        #The subject of the email

#Below is the default contents of the email including the variables entered   above.
$Body = "                         
New/Replacement Token Request:



Dealer Name: $DealerName


Dealer Code: $DealerCodeLookup


Location: $locale
(office name)


Address: $Adrs


Dealer Email:


Amount of Soft Tokens Needed: $SoftTokenAmount


Reason for Request: $Reason"

#This final chuck is the actual sending an email smtp information for gmail
$SMTPServer = "smtp.office.com"
$SMTPPort = "587"
$secpasswd = ConvertTo-SecureString "publicpass" -AsPlainText -Force 
$mycreds = New-Object System.Management.Automation.PSCredential     ("TokenRequest@whereiwork.com", $secpasswd)

Send-MailMessage -From $From -to $To -Subject $Subject `
-Body $Body -SmtpServer $SMTPServer -dno onSuccess, onFailure  -port     $SMTPPort -UseSsl `
-Credential  $mycreds 
#= New-Object System.Management.Automation.PSCredential     ("TokenRequest@whereiwork.com", $secpasswd)
#(new-object System.Net.NetworkCredential("scott","","ccin****.com"))
#(Get-Credential) #<- this line prompts for the outlook  login of the     default email (mine.) User is jacob@r**** and password is 8888!
Send MailMessage:找不到接受参数“=”的位置参数。 在G:\tokenrequest v2.0.ps1:144 char:1 +发送邮件消息-从$From-到$to-Subject$Subject` + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +CategoryInfo:InvalidArgument::[Send MailMessage],参数BindingException
+FullyQualifiedErrorId:PositionParameterNotFound、Microsoft.PowerShell.Commands.SendMailMessage似乎需要在from主题周围有一个“标记”才能正确传递