TFS Query or SQL Query to Identify Empty Test Plans or Empty Test Suites - tfs-2015

We are fairly new to TFS and I have been trying to clean up some of the areas. I can see through a simple TFS query that there are over 180 Test Suites with the name "New suite"... I don't want to try to open each one and look to see if there are test cases assigned to it.
Is there a way to get a report of Empty Test Suites, and maybe Empty Test Plans?
Thanks
Pat

You can use REST API to Get a list of test suites, "testCaseCount" will be included in the response. See below example:
GET https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/fabrikam-fiber-tfvc/_apis/test/plans/1/suites?api-version=1.0
For more information please refer to https://www.visualstudio.com/en-us/docs/integrate/api/test/suites
Besides, you can also get the empty Test Suites or Test Plans by running the sql query in SQL Server, see below sample.
SELECT
[SuiteId]
,[PlanId]
,[ParentSuiteId]
,[Title]
,[TestCaseCountFromMtm]
,[TestCaseCountFromWeb]
FROM [Tfs_CollectionLC].[dbo].[tbl_Suite]
WHERE [TestCaseCountFromMtm]='0' and [TestCaseCountFromWeb]='0'
Update:
If you want to get the Plan and Parent Suite name, in above query the "Title" column will display all the suite name including the Parent Suite name. I didn't find the exact table to get the Plan name, but we can get it via REST API, you can use below sample PowerShell script to get all the Test Plan names. Just copy/paste the script and save it as .ps1 file to run on your client.
$project = "TFVC-Scrum" # Change to your team project name here
$baseUrl = "http://12r2:8080/tfs/CollectionLC" # Change to your TFS Collection URL
$testplanUrl = "{0}/{1}/_apis/test/plans?api-version=1.0" -f $baseUrl, $project
$TestPlans = (Invoke-RestMethod -Uri $testplanUrl -Method Get -UseDefaultCredential).value
$TestPlanResults = #()
foreach($TestPlan in $TestPlans){
$testplanitemUrl = "{0}/{1}/_apis/test/plans/{2}?api-version=1.0&includeDetails=true" -f $baseUrl,$project, $TestPlan.id
$TestPlanItem = Invoke-RestMethod -Uri $testplanitemUrl -Method Get -UseDefaultCredential
$customObject = new-object PSObject -property #{
"TestPlanid"= $TestPlanItem.id
"TestPlanName"= $TestPlanItem.name
}
$TestPlanResults += $customObject
}
$TestPlanResults | Select `
TestPlanid,
TestPlanName

Related

How to correctly store SQL data in a variable?

So I am currently writing a script to create a Jira Issue every morning with all the aborted processes of our Adeptia Broker's. All of this works, except for the part that I get the SQL data and get it into the Jira issue's description.
This is what I use to collect the SQL Server Data a the moment;
$SELECTQUERY = "
SELECT DISTINCT COLUMN, COLUMN, COLUMN, COLUMN
FROM [$DB].[dbo].[$TABLE]
WHERE COLUMN= 'x' AND COLUMN = 'x'
ORDER BY COLUMN DESC
"
try {
# Run SQL Query
Invoke-Sqlcmd -ServerInstance $SI -Database $DB -Username $UID -Password $PASS -Query $SELECTQUERY
$test = $SELECTQUERY.output
CreateJiraIncident -summary $summary -description $test
}
catch {
# Error handling
Write-Warning -Message "Well, the script didn't work..."
break
}
Whenever I call the $SELECTQUERY.output with echo, return or Write-Host it gives me back the correct data. Does anyone know of a different way to store this data in a string so I can send it off to Jira? (No the issue isn't with the Jira part since I can add anything I want to the 'description' parameter it will show up in the Jira Issue.
I really just need a way to store all this data in a string so I can correctly send it.

How to read/fetch data from Oracle SQL database using PowerShell Core?

I have been researching on this for a couple of days but have been going in circles here.
I need to write a script that fetches the data from Oracle db and do something with the data. In my script I will have to fetch data multiple times.
My machine has the SQLDeveloper-21.4.3 which I got from installing InstantClient-Basic-Windows-21.3.0. I use the SQL Developer to connect to the db which is on another machine; this is how I can look into tables, views etc. of the db.
Secondly, this script will be hosted on another server that runs Windows-Server-2012-R2. I am just using my machine to write the script because I cannot use the server to do this. Therefore, I am looking for a solution that requires minimum amount of installing.
Thirdly, we do not have Oracle commercial license. This Oracle db I am trying to access is on the machine installed by a third party that installed some instruments. This company uses Oracle as they collect data on the instruments installed.
I was hoping the solution would be something similar to invoking connection to MS SQL where I downloaded module that gave cmdlets to connect to the MS SQL.
Oracle does have Oracle Modules for PowerShell but neither have I found information on how to use them nor have I understood the little information provided by Oracle on this. For this to work one of the requirement is:
A configuration file and key pair used for signing API requests, with
the public key uploaded to Oracle Cloud using Oracle Cloud
Infrastructure Console. Only the user calling the API should possess
the private key.
I don't know the heck Oracle is talking about here. Like, what is this configuration file, where is it? Where would I get the key pair from for signing API request. What is Oracle Infrastructure Console, where do I get it from? You get the idea.
Link: https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/powershell.htm
Therefore, I went the .DLL route.
This is what I have done so far:
I installed Oracle.ManagedDataAccess.Core -Version 3.21.61 from NuGet.
Unzipped the package and moved the Oracle.ManagedDataAccess.dll to the location of my script.
The code is:
$OracleDLLPath = "C:\Users\Desktop\CNC_File_Transfer_VSCode\Fastems_NicNet\Oracle.ManagedDataAccess.dll"
$datasource = " (DESCRIPTION =
(ADDRESS =
(PROTOCOL = TCP)
(HOST = 10.50.61.9)(PORT = 1521))
(CONNECT_DATA = (SERVER = DEDICATED)
(SERVICE_NAME = Fa1)
(FAILOVER_MODE = (TYPE = SELECT)
(METHOD = BASIC)
(RETRIES = 180)
(DELAY = 5))))"
$username = "username"
$password = "password"
$queryStatment = "SELECT [PROG_TYPE] FROM NC_PROGRAMS FETCH FIRST 10 ROWS ONLY"
#Load Required Types and modules
Add-Type -Path $OracleDLLPath
Import-Module SqlServer
Write-Host $queryStatment
#Create the connection string
$connectionstring = 'User Id=' + $username + ';Password=' + $password + ';Data Source=' + $datasource
#Creates a data adapter for the command
$da = New-Object Oracle.ManagedDataAccess.Client.OracleDataAdapter($cmd);
#The Data adapter will fill this DataTable
$resultSet = New-Object System.Data.DataTable
#Only here the query is sent and executed in Oracle
[void]$da.fill($resultSet)
#Close the connection
$con.Close()
WRITE-HOST $resultSet
This gives an error though:
Add-Type : Unable to load one or more of the requested types. Retrieve
the LoaderExceptions property for more information.
I am new to programming in general. I would really appreciate if someone could provide detailed steps on resolving this. Thanks in advance.

Azure PS command returns empty list

We have created a resource group with a VMSS instance within.
When running the "az vmss list" command within the Cloud Shell, we are able to get the respective resource.
However, when running the exact same command in PS, it returns an empty list, even though the resource exists.
We have also created a different naming convention and used the ARM Api call to test this and we got the same outcome. See the command below:
Invoke-RestMethod -Uri https://management.azure.com/subscriptions/***/resourceGroups/***-nodepool-prd-devtest/providers/Microsoft.Compute/virtualMachineScaleSets?api-version=2020-12-01 -Method GET -Headers $headers -ContentType 'application/json'
Output:
value
-----
{}
We have tried to add another VMSS to the same resource group as a test and noticed that made the other one pop up.
It looks to me as if it is a caching issue but I can't figure out how to resolve it. Any ideas?
Things to keep in mind:
using the same CLI version as Cloud Shell (2.23.0)
running the command from the pipeline returns an empty list
a team member is able to get the resource from their own machine
I saw the similar issue when a specific subscription wasn't show up in a list of output.
We used below ps commands to resolve the issue:
Disable-AzureRmContextAutosave
Disconnect-AzureRmAccount
As you use the Az module, please try these:
Disable-AzContextAutosave
Disconnect-AzAccount
Source: https://github.com/Azure/azure-powershell/issues/6289
PS: it seems you need to edit the title to the "Azure PS command returns empty list"

TFS 2013 linking Test Case Associated Automation to xUnit tests

I'm wondering if it is possible to link Test Cases in TFS 2013 to xUnit tests. Currently it works fine for msTest tests but once I change the method attribute from 'TestMethod' to 'Fact' and rebuild the test no longer appears when I click the Associated Automation in the Test Case to link the two together.
Has anybody any experience or answers for this?
Thanks
It is possible with the TFS API. This PowerShell script show you how to do that (see: https://blogs.msdn.microsoft.com/gautamg/2012/01/01/how-to-associate-automation-programmatically/ for reference).
# Get TC
$tfsTpc = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($TPC_URL)
$tms = $tfsTpc.GetService([Microsoft.TeamFoundation.TestManagement.Client.ITestManagementService])
$tp = $tms.GetTeamProject($TP_NAME)
$tc = $tp.TestCases.Find($tcId)
# Compute Automation Guid
$sha1Crypto = new-object System.Security.Cryptography.SHA1CryptoServiceProvider
[Byte[]] $bytes = New-Object Byte[] 16
[Array]::Copy($sha1Crypto.ComputeHash([System.Text.Encoding]::Unicode.GetBytes($testName)), $bytes, $bytes.Length)
# Create association
$tc.Implementation = $tp.CreateTmiTestImplementation($testName, $AUTOMATION_TYPE, $AUTOMATION_STORAGE_NAME, $automationGuid)
$tc.Save()
$automationGuid = New-Object -TypeName Guid -ArgumentList #(,$bytes)
But you will not be able to associate the execution with the Test Case in TFS.
The test must be run with MSTest V1 to log results as a valid TRX to be published in TFS through TCM.exe. Even with vstest.console.exe and the TRX logger option the xml result is not understandable by TCM.exe.
For reference see: http://bugsareinthegaps.com/uploading-automated-test-results-to-mtm-made-easy/

Powershell to find the principal/mirror in SQL servers

I would like to know if it is possible to know if a instance of sql server is in mirror/prinicipal by running any sql query? and secondly i want to run this on say 60-80 instances everyday at 4am automatically possible? I would like to use powershell used it before quite easy to use from experience. Tks
It is possible. You will need to play around with SMO objects.
$server = "dwhtest-new"
$srv = New-Object Microsoft.SqlServer.Management.Smo.Server $server
$db = New-Object Microsoft.SqlServer.Management.Smo.Database
$dbs = $srv.Databases
foreach ($db1 in $dbs)
{
$db = New-Object Microsoft.SqlServer.Management.Smo.Database
$db = $db1
$DatabaseName = $db.Name
Write-Host $DatabaseName
Write-Host "MirroringStatus:" $db.MirroringStatus
Write-Host "DBState:" $db.Status
Write-Host
}
If your DB's mirroring is still intact you will recieve 'Synchronized' for MirroringStatus and its its the Primary it will say "Normal" for the status and if its the failover it will say "Restoring". Unfortunately there is no way, that im aware of, to just pull out the status of "Mirror" or "principle". You will jsut have to build logic to check both fo those values.
Restoring
It depends on how are you going to setup the job?
If you want to run it from one central server that collects all the information then SMO would be the way to go with PowerShell. The answer provided by KickerCost can work but would need some more work to be able to run it for multiple servers. It would be best to take his example and turn it into a working function that will allow the server names to be piped in.
If you are going to just run a job locally on each server (scheduled task or SQL Agent job) that may point to the script on a network share, then maybe output that info to a file (like servername_instance.log) you can use a one-liner with SQLPS:
dir SQLSERVER:\SQL\KRINGER\Default\Databases | Select Name, MirroringStatus
KRINGER is my server name, with a default instance. If you have named instances then replace the "default" with the instance name.
Your output from this command would be similar to this:
Name MirroringStatus
---- ---------------
AdventureWorks None
AdventureWorksDW None
Obviously I don't have any databases involved in mirroring.