• Change these two lines in your script to make it 2012 compatible -

    -- Read physical memory on server

    SET @TotalMEMORYinBytes = (select physical_memory_kb from sys.dm_os_sys_info)

    -- Coverting value from bytes to megabytes

    SET @TotalMEMORYinMegaBytes = (@TotalMEMORYinBytes /(1024))