Hello
I keep getting the error about null array and as such I won't let me update my SQL.
As for the HOTSKP036 is the computer I'm using to remote access the Windows 2012 R2 server it is not in any of the .txt
C:\Scripts\ServerScripts\TEST SERVER SCRIPTS\TEST IN THIS BEFORE GOING FOR.ps1
WARNING: HOTSKP036: Cannot index into a null array.
[string]$SqlServer = 'DC01' [string]$Database = 'class1' [int]$ConnectionTimeout = 30 [int]$QueryTimeout = 120 $serv = Get-Content "\\DC01\ServerScripts\Computers.txt" invoke-command -computerName $serv -scriptBlock { start-service RemoteRegistry } Write-Verbose ("Creating SQL Connection to {0}" -f $sqlServer) #Opening connection to sql server $sqlConnection = New-Object System.Data.SqlClient.SqlConnection $sqlConnection.ConnectionString = "Server=$SqlServer;Database=$Database;Integrated Security=SSPI;Persist Security Info=False; User ID=CLASS1\administrator;Initial Catalog=class1;Data Source=DC01\SQLEXPRESS" $sqlConnection.Open() Try { $WMI['Computername'] = $Computer $server = ForEach ($Computer in Get-Content "\\DC01\ServerScripts\Serverslist.txt") # Getting Information about servernames needed to be run in the script { $Month = (Get-Date -Format MMMM).ToString() # Gives the Fullname of the month the script is run in. #Finding the HDD Info that exits on the Servers $Item = @("Name", "MediaType", "Capacity", "FreeSpace") #Clear-Host # Next follows one command split over four lines by a backtick ` Get-WmiObject -computername $Computer -query `"Select $([string]::Join(',',$Item)) from Win32_logicaldisk ` Where MediaType=12" | Sort-Object MediaType, DeviceID ` | Format-Table $item -auto #Used for finding RaidStatus and if it is healthy $raidvalues = get-wmiobject -class win32_systemdriver | where-object {$_.displayname -like "*mraid*"} Write-Host "Raid Config Status is " $raidvalues.Status $CPUInfo = ((Get-WmiObject Win32_Processor -ComputerName $Computer).MaxClockSpeed)/1000 #Get CPU Information $OSInfo = Get-WmiObject Win32_OperatingSystem -ComputerName $Computer #Get OS Information #Get Memory Information. The data will be shown in a table as GB, rounded to the nearest second decimal. $OSTotalVirtualMemory = [math]::round($OSInfo.FreePhysicalMemory / 1024 /1024, 2) $OSTotalVisibleMemory = [math]::round(($OSInfo.TotalVisibleMemorySize / 1024 /1024), 2) $PhysicalMemory = Get-WmiObject CIM_PhysicalMemory -ComputerName $Computer | Measure-Object -Property capacity -sum | % {[math]::round(($_.sum / 1GB),2)} $usage = (get-counter -Counter "\Processor(_Total)\% Processor Time" -SampleInterval 1 -MaxSamples 2 | select -ExpandProperty countersamples | select -ExpandProperty cookedvalue | Measure-Object -Average).average #$usage = "{0:P}" -f $usage #This function is for getting data from the CPU on how many cores the server has. Function Get-CPUs { param ($Computer) $processors = get-wmiobject -computername $Computer win32_processor $cores=0 if (@($processors)[0].NumberOfCores) { $cores = @($processors).count * @($processors)[0].NumberOfCores } else { $cores = @($processors).count } $sockets = @(@($processors) | % {$_.SocketDesignation} |select-object -unique).count; } # Space for Antivirus part. #The start for inputing to our Database Table. $Data = @(Get-WmiObject @WMI) $Data | ForEach { Write-Verbose ("{0}-{1}: Updating in SQL database" -f $Computer,$_.Name) $Command = "INSERT INTO [dbo].[ServerInfoTable] (Servername,Month,CPU,Cores,CPUusage,Memorytotal,Memoryused, DeviceID,size,FreeSpace,UsedSpace,RAIDFabrikant,RAIDStatus,AntiVirusVersion,AntiVirusDefination) ` VALUES ('$($Computer)', '$($Month)', '$($CPUInfo)', '$(($cores),($sockets))', '$($usage)', '$($PhysicalMemory)', '$($PhysicalMemory - $OSTotalVirtualMemory)', '$($_.Name)', '$(([Math]::round($_.Capacity/1GB,2)))', '$(([Math]::round($_.FreeSpace/1GB,2)))', '$(([Math]::round(($_.Capacity - $_.FreeSpace)/1GB,2)))', '$($_.displayname)', '$($raidvalues.Status)', '$(($productName),($productVersion))', '$($productDefination)')" $cmd=new-object system.Data.SqlClient.SqlCommand($Command,$sqlConnection) $cmd.CommandTimeout=$QueryTimeout $cmd.ExecuteNonQuery() | Out-Null } } } Catch { Write-Warning ("{0}: {1}" -f $Computer, $_.Exception.Message) } Write-Verbose ("Closing connections") #Closing the sql server connection if ($sqlConnection.State -eq [Data.ConnectionState]::Open) { $sqlConnection.Close() }