locked
Comparing SQL output with a variable value RRS feed

  • Question

  • Hi All , 

    I am trying to get count from SQL and then comparing it against a variable .

    $sitecount= Invoke-Sqlcmd -Query "Select COUNT(*) from XXXXXX where CCCC = 0" -ServerInstance YYYY

    $getcount= (get-Childitem -Force C:\abd\fg\test01 |select-object name).count

    if ($sitecount -eq $getcount){

    do this }

    else

    {

    do this

    }

    The value for $sitecount is coming as system.data.datarow and i am unable to compare it with against my files count . How do i make this possible............ ?

    Friday, December 26, 2014 2:33 PM

Answers

  • PS >$sitecount= Invoke-Sqlcmd -Query "Select COUNT(*) As Count from XXXXXX where CCCC = 0" -ServerInstance YYYY
    PS >$sitecount.Count
    133


    ¯\_(ツ)_/¯

    • Proposed as answer by jrv Friday, December 26, 2014 3:04 PM
    • Marked as answer by AnnaWY Wednesday, January 7, 2015 2:34 AM
    Friday, December 26, 2014 3:04 PM