Forum Discussion
yamina786
Jul 07, 2022Copper Contributor
Run powershell script on Devops with paramter
We have created below script which is exporting send port details from binding file post deployment and then comparing the send port name from a csv lookup sheet we are exporting a new csv file having some interface details.
so the script is working fine when we are running on the server but we are trying to run the same script in azure Devops pipeline mentioned the script path and argument then it failing with below error.
Script running fine in server:
$finalBinding = [xml](Get-Content 'D:\agent\BIZTALK_DEPLOY1\r17\a/_BOS.DMS.Parts.Master/drop/Binding.xml')
$finalBinding.BindingInfo.SendPortCollection.SendPort.Name | out-file "C:\Script\test.csv"
import-csv "C:\Script\test.csv" -Header SendPort | sort SendPort | export-csv "C:\Script\output.csv" -NoTypeInformation
Remove-Item –path "C:\Script\test.csv"
$BindingData = Import-Csv -Path "C:\Script\output.csv"
$LookupData = Import-Csv -Path "C:\Script\Interfacedetails.csv"
$UserOutput = @()
ForEach ($name in $BindingData)
{
$userMatch = $LookupData | where {$_.SendPort -eq $name.SendPort}
If($userMatch)
{
$UserOutput += New-Object PsObject -Property @{InterfaceName=$userMatch.InterfaceName;ApplicationTo=$userMatch.ApplicationTo;ApplicationFrom =$userMatch.ApplicationFrom;InterfaceID=$userMatch.InterfaceID;DataObject=$userMatch.DataObject}
}
}
$UserOutput | export-csv "C:\Script\FILE.csv" -NoTypeInformation
Import-CSV C:\Script\FILE.csv | Select-Object InterfaceName, InterfaceID, DataObject, ApplicationFrom, ApplicationTo | Export-CSV C:\Script\ExportedCSV\Final.csv -NoTypeInformation
Remove-Item –path "C:\Script\FILE.csv"
Remove-Item –path "C:\Script\output.csv"
Running the same script with Argument:
$finalBinding = [xml](Get-Content –path $bindingpath)
$finalBinding.BindingInfo.SendPortCollection.SendPort.Name | out-file "C:\Script\test.csv"
import-csv "C:\Script\test.csv" -Header SendPort | sort SendPort | export-csv "C:\Script\output.csv" -NoTypeInformation
Remove-Item –path "C:\Script\test.csv"
$BindingData = Import-Csv -Path "C:\Script\output.csv"
$LookupData = Import-Csv -Path "C:\Script\Interfacedetails.csv"
$UserOutput = @()
ForEach ($name in $BindingData)
{
$userMatch = $LookupData | where {$_.SendPort -eq $name.SendPort}
If($userMatch)
{
$UserOutput += New-Object PsObject -Property @{InterfaceName=$userMatch.InterfaceName;ApplicationTo=$userMatch.ApplicationTo;ApplicationFrom =$userMatch.ApplicationFrom;InterfaceID=$userMatch.InterfaceID;DataObject=$userMatch.DataObject}
}
}
$UserOutput | export-csv "C:\Script\FILE.csv" -NoTypeInformation
Import-CSV C:\Script\FILE.csv | Select-Object InterfaceName, InterfaceID, DataObject, ApplicationFrom, ApplicationTo | Export-CSV C:\Script\ExportedCSV\Final.csv -NoTypeInformation
Remove-Item –path "C:\Script\FILE.csv"
Remove-Item –path "C:\Script\output.csv"
I have declared the variable for $bindingpath = $(System.DefaultWorkingDirectory)/_BOS.DMS.Parts.Master/drop/Binding.xml
But its failing with below error:
Formatted command: . 'C:\Script\powershellscript.ps1' System.DefaultWorkingDirectory/_BOS.DMS.Parts.Master/drop/Binding.xml
2022-07-05T11:09:43.7113613Z ========================== Starting Command Output ===========================
2022-07-05T11:09:43.7250585Z ##[command]"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'D:\agent\BIZTALK_DEPLOY1_temp\9b6ede3b-af5a-4813-9fc9-9d343c347be2.ps1'"
2022-07-05T11:09:44.0505059Z At C:\Script\powershellscript.ps1:24 char:15
2022-07-05T11:09:44.0505593Z + Remove-Item –path C:\Script\output.csv
2022-07-05T11:09:44.0505849Z + ~~~~~~~~~~~~~~~~~~~~~~~~~~
2022-07-05T11:09:44.0506103Z The string is missing the terminator: ".
2022-07-05T11:09:44.0506460Z + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
2022-07-05T11:09:44.0507271Z + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
please help me to resolve the issue.
- BobRichleyCopper ContributorCheck this –path. It looks like an elongated dash. Replace with -path.