1

I run Test-SPContentDatabase like this:

  public string Test_Associate(string DbName,string UrlApp) {


        Runspace runspace = RunspaceFactory.CreateRunspace();

        // open it
        runspace.Open();

        using (PowerShell powerShell = PowerShell.Create())
        {
            powerShell.Runspace = runspace;

            powerShell.Runspace.SessionStateProxy.SetVariable("DbName", DbName);
            powerShell.AddScript("$DbName");

            powerShell.Runspace.SessionStateProxy.SetVariable("urlApp", UrlApp);
            powerShell.AddScript("$urlApp");

            powerShell.AddCommand("Set-ExecutionPolicy").AddArgument("Unrestricted");
            powerShell.AddScript(Environment.CurrentDirectory + @".\Data_tier\PS1\Test_Association.ps1");

            Collection<PSObject> results = powerShell.Invoke();

            // convert the script result into a single string
            StringBuilder stringBuilder = new StringBuilder();
            foreach (PSObject obj in results)
            {
                stringBuilder.AppendLine(obj.ToString());
            }
            runspace.Close();
            return stringBuilder.ToString();

        }
    }

My ps1 file:

    if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) 
{
    Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}
Test-SPContentDatabase -Name $DbName -WebApplication $urlApp

But the result doesn't returns a list of issues. it return : "Microsoft.SharePoint.Upgrade.SPContentDatabaseTestResult" . how can I get the list of issues. best reagards

4

Try this,

Test-SPContentDatabase -Name $DbName -WebApplication $urlApp > C:\\TextResults.txt

or

Test-SPContentDatabase -Name $DbName -WebApplication $urlApp > C:\\TextResults.xml

it should create a result file in C drive.

Edit

Right way,

Test-SPContentDatabase -Name $DbName -WebApplication $urlApp | Out-File c:\TestResult.txt

Seems like >> opens and closes file for each line, however Out-File just opens and closes the file just once as stated in this post.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.