Skype for Business System Status Script Help

Hello - I’m new to the forum, as well as Powershell. For the most part I’ve gotten through the script, but for some reason it now throws an error that I hadn’t seen before.

Errors:

Cannot convert value "Not collected" to type "System.Int32". Error: "Input string was not in a correct format."
At C:\Users\a-ckrafcky\Desktop\SystemStatus\SystemStatus.ps1:1712 char:7
+             $intErrors = [int]$_.Errors
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvalidCastFromStringToInteger

Cannot convert value "Not collected" to type "System.Int32". Error: "Input string was not in a correct format."
At C:\Users\a-ckrafcky\Desktop\SystemStatus\SystemStatus.ps1:1729 char:7
+             $intWarnings = [int]$_.Warnings
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvalidCastFromStringToInteger

Cannot convert value "Not collected" to type "System.Int32". Error: "Input string was not in a correct format."
At C:\Users\a-ckrafcky\Desktop\SystemStatus\SystemStatus.ps1:1712 char:7
+             $intErrors = [int]$_.Errors
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvalidCastFromStringToInteger

Cannot convert value "Not collected" to type "System.Int32". Error: "Input string was not in a correct format."
At C:\Users\a-ckrafcky\Desktop\SystemStatus\SystemStatus.ps1:1729 char:7
+             $intWarnings = [int]$_.Warnings
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvalidCastFromStringToInteger

Cannot convert value "Not collected" to type "System.Int32". Error: "Input string was not in a correct format."
At C:\Users\a-ckrafcky\Desktop\SystemStatus\SystemStatus.ps1:1712 char:7
+             $intErrors = [int]$_.Errors
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvalidCastFromStringToInteger

Cannot convert value "Not collected" to type "System.Int32". Error: "Input string was not in a correct format."
At C:\Users\a-ckrafcky\Desktop\SystemStatus\SystemStatus.ps1:1729 char:7
+             $intWarnings = [int]$_.Warnings
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvalidCastFromStringToInteger

If the whole code is required, what is the allowed format to get it into the post?

Ouch … 1700+ lines of code? How about starting with line number 1712 and 1729, the ones generating the errors.

1 Like
#Check out state of errors - 7
		#--------------------------------
		If ($_.Errors -ne "n/a" -and ($_.Errors -match "[0-9]*")){
		    $intErrors = [int]$_.Errors
		} Else {
		    $intErrors = 0
		}
		if ($intErrors -gt 10) {
			$strColour = "#ff0000"
		} Else {
			$strColour = "#66CD00"
		}
		$strHTMLRowNew = $strHTMLRowNew -Replace "\<ERRORS\>",$_.Errors
		$strHTMLRowNew = $strHTMLRowNew -Replace "\<COLOUR7\>",$strColour
		$strDescription = $_.Description + ";$intErrors"
		#--------------------------------
        
        #Warnings - 8
		#--------------------------------
		If ($_.Warnings -ne "n/a" -and ($_.Warnings -match "[0-9]*")){
		    $intWarnings = [int]$_.Warnings
		} Else {
		    $intWarnings = 0
		}
		if ($intWarnings -gt 50) {
			$strColour = "#ff0000"
		} Else {
			$strColour = "#66CD00"
		}
		$strHTMLRowNew = $strHTMLRowNew -Replace "\<WARNINGS\>",$_.Warnings
		$strHTMLRowNew = $strHTMLRowNew -Replace "\<COLOUR8\>",$strColour
		$strDescription = $_.Description + ";WARN-$intWarnings;"
        #--------------------------------
        
        #$strColour = "#ffd700"
		#$strHTMLRowNew = $strHTMLRowNew -Replace "\<GATEWAY\>",$_.Gateway
		```

type or paste code here

ckrafcky10,
Welcome back to the forum. :wave:t4:

If you expect specific help you should share the specific part of your code producing this errors. :wink:

In genereal: it seems like you provide a string "Not collected" where your script expects an integer.

Just format it like you formatted the eror message you posted. :wink:

Thanks for the quick replies. I’ve provided the portion of code as a reply to tonyd. Bear in mind that I didn’t write this code, I am just trying to decipher it and get it to do what I’d like.

So you may ask the author of the code to help you debugging it!? :face_with_raised_eyebrow:

Obviously your variable $_.Errors containes more than just numbers or just numbers greater than an [INT] allowes.

The code is forcing a type cast of Integer to [Int]$_.Errors. It looks like there is a match for 0-9, but also contains string values as well. The first thing I would try is removing the type cast and see what happens.

$intErrors = $_.Errors
$intWarning = $_.Errors