1

I am trying to write a query to see if a workspace with specific name already exists in repository or not. Following is the query I am using after logging in a previous command:

$wsQueryResult = &scm query -r https://myrationaluri -w "name='myworkspace"

I get output similar to following:

At C:\scripts\vso-rtc\get-code-fromRTC.ps1:27 char:19
+  $wsQueryResult = &scm query -r myurl -w "name='my ...
+                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Problem running 'query'::String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
No repository workspace matches the query "name='myworkspace'".

The query is inside a powershell script. I understand the last part of the response "No repository workspace matches the query..." However, why do I get Problem running query::String. The value of $wsQueryResult is null after this execution. I was hoping that there will be an exit code or something.

Is the problem in my query syntax or is this normal. If it is normal, do I need to examine the output for line "no repository workspace"

Thank you for your help.

Machavity
  • 30,841
  • 27
  • 92
  • 100
sohail
  • 589
  • 1
  • 11
  • 26

1 Answers1

1

I ended up examining the output from query and determining if the workspace was found or not. I used following code:

 $workspaceName = $env:USERNAME + "-" + $patch
 $output=scm query -r $rtcURI -w "name='$workspaceName'" *>&1
 $output = $output | Select-String "No repository workspace matches"
 if ($output -like "No repo*") {
   write-host "Repository doesn't exist, will create new one"
   scm create workspace -r $rtcURI -s $streamName $workspaceName
 } else {
   write-host "Workspace $workspaceName Already exists... will refresh"
 }
sohail
  • 589
  • 1
  • 11
  • 26