Skip to content

Instantly share code, notes, and snippets.

@buaziz
buaziz / psGetFileNameWithoutExtension.ps1
Created April 10, 2020 19:20
PowerShell DevOps Task - Get file name without Extension and set Task Variable
$input_path = "C:\Folder-to-Search\"
foreach($file in Get-ChildItem -Path $input_path -Recurse -Include *.cs)
{
Write-Output "fileName : $($file.BaseName)"
Write-Host "##vso[task.setvariable variable=DevOpsVariableToSet;]$($file.BaseName)"
}
@buaziz
buaziz / psExtractBetweenQuotes.ps1
Created April 10, 2020 19:15
PowerShell - Extract Text Between Quotes
$input_path = "C:\file-to-search.txt"
#$output_file = "C:\output.txt"
$regex = '(?<=")(?:\\.|[^"\\])*(?=")'
$versionNumber = select-string -Path $input_path -Pattern $regex -AllMatches | ForEach-Object { $_.Matches } | ForEach-Object { $_.Value }
Write-Output "versionNumber : $versionNumber"