Hi , hope someone can shed some light on what is wrong here. I have a script that captures SQL Server config details and saves them to SQL table. Stats collected by powershell. The script runs fine on 80% of my servers so far. The for some reason I get this error when running against some machines. This is the error I get : You cannot call a method on a null-valued expression. At C:\DBAScripts\Upsert-Server.ps1:278 char:36 + $strErrorLog=( $strParameters.Split <<<< (";") | where {$_.StartsWith("-e")} ) + CategoryInfo : InvalidOperation: (Split:String) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull And error You cannot call a method on a null-valued expression. At C:\DBAScripts\Upsert-Server.ps1:279 char:61 + $strUpsertSql = $strUpsertSql + "'" + $strErrorLog.Substring <<<< (2, $strErrorLog.Length-2) + "', " + CategoryInfo : InvalidOperation: (Substring:String) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull This is the 2 lines of code in the script that is called. $strErrorLog=( $strParameters.Split(";") | where {$_.StartsWith("-e")} ) $strUpsertSql=$strUpsertSql+"'"+$strErrorLog.Substring(2, $strErrorLog.Length-2) +"', " Now the code has worked for about 30 machines with no changes. I now get to a few where it fails. What is the error telling me , and what do I need to check or change in order for it to work ? Had a look at various comparisons on each machine and can see no differences…..most confused. Appreciate any help or advice. Think I am stuck here.
↧
Powershell error.....but it works sometimes !
↧