In the below powershell script I am passing three string parameters. The $ComputerName parameter line works as expected. I am able to remote into the machine that I specify.
Issue 1
On the line $latestbuildfolder I am using $builddefinition parameter to specify build definition. It appends the name of the builddefinition but does not list folder inside that folder. If I replace $BuildDefinition parameter by “TeamBuild” our build definition name then it is able to list all the folders and get the latest folder. Some how I feel the join is not working. I have tried using Join-Path too and still not working.
Issue 2
On the line $deploycmdlocation when I try to specify $Configuration in that string it is not working. It outputs a blank between that path. I checked using Write-Host and the parameters is passed to the script.
param(
[System.String] $ComputerName,
[System.String] $Configuration,
[System.String] $BuildDefinition
)
$session = New-PSSession -ComputerName $ComputerName
Invoke-Command -Session $session -ScriptBlock {
$latestbuildfolder = Get-ChildItem "C:\procmon\procmonBuilds\$BuildDefinition" | Sort-Object LastWriteTime -Descending | SELECT-Object -First 1
$deploycmdlocation = "\procmon\procmonWebProject\$Configuration\_PublishedWebsites\procmonWebProject_Package\procmonWebProject.zip"
$finalstring = $latestbuildfolder.FullName + $deploycmdlocation
$finalstring
}
Remove-PSSession $session
I have tried lots of options and still no luck so far.
The solution that worked for me just felt like Inception movie. It turns out that I have to declare param at two places. Thanks to my co-worker friend for this solution.
Here is the final script that works for me. This is a script that runs on build machine and then does a new-pssession on remote computer get web packages from latest build drops folder. Those parameters are passed through process template activity Invoke-Process used to invoke powershell scripts.