Ниже приведен код для внутреннего инструмента, на котором я был назначен ответственным за настройку. Он в основном ссылается на электронную таблицу, основанную на известном значении, и использует часть этой информации для целей сортировки и использует другую информацию для заполнения автоматизированной электронной почты. У меня было несколько версий его работы, но кажется, что по какой-либо причине он действует так, как одна из переменных не заполняется или больше не принимает строку как допустимый тип данных. Я довольно новичок в обмене стеками, поэтому, если есть какое-либо форматирование или что-то, что я могу сделать, чтобы прояснить, что, похоже, проблема, я буду рад обязать вас.Кажется, я получаю ошибку позиционного параметра с mailmessage в powershell по адресу 144
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 = "[email protected]"
}
#This loop is for the CentralArea
Elseif($State -like '*TN*' -or ($State -like '*GA*'))
{
$To = "[email protected]"
}
#This loop is for the WesternArea
Elseif($State -like '*CO*' -or ($State -like '*UT*'))
{
$To = "[email protected]"
}
$From = "[email protected]" #Default from email, mine.
#$Cc = "[email protected]" #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 ("[email protected]", $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 ("[email protected]", $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 [email protected]**** and password is 8888!
Send-MailMessage: Позиционный параметр не может быть найден, который принимает аргумент '='. В G: \ Token Request v2.0.ps1: 144 char: 1 + Send-MailMessage -From $ From-to $ To -Subject $ Subject ` + ~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo: InvalidArgument: (:) [Send-MailMessage], ParameterBindingException + FullyQualifiedErrorId: PositionalParameterNotFound, Microsoft.PowerShell.Commands.SendMailMessage