The technique of disecting the light of a celestial (or any other) light-emitting source into its "rainbow colours", by using e.g. a dispersive element such as a prism, is called "spectroscopy". An obvious example is the spectrum of the visible (="optical") light we receive from the Sun.
Studies of the physics of an emitting/absorbing medium
For most applications it is not practical to display a true-colour spectrum. Instead, astronomers normally use only a line graph. One can imagine the creation of such a line graph by cutting through the above spectrum from left to right and then plotting against the X-position the intensity values measured along the way. Such a line graph display of a spectrum is shown below (note: the x-axes don't quite match; the upper ranges from below 4000 to above 7500 Angstroms, the one below from 300 to 900 Nanometres [10 Angstrom = 1 Nanometre]).
Now one can distinguish much more easily distinct features in the spectrum that are lost to the eye in a two-dimensional colour display. Several absorption lines are visible as dips.
These spectral features, combined with theoretical models and predictions based on fundamental particle physics, allow us to deduce a wealth of information about the emitting object. Emission and absorption line properties are particularly useful diagnostic tools, because they vary for different conditions of the emitting medium.
Usually, although not as intuitive for the untrained eye, spectra contain a lot more information than images. The following figure displays an optical spectrum of the centre of a so-called "starburst" galaxy. A starburst galaxy produces large numbers of massive stars on a relatively short timescale. The total spectrum of such a galaxy's central area is then dominated by emission characteristics of relatively young stars (and can often be approximated quite well with a stellar template spectrum). However, there are not only spectral lines in the optical regime. A plethora of other lines is observed, e.g. also in the X-ray part of the electromagnetic spectrum. Below I display a high-resolution X-ray spectrum of the central starburst in the southern galaxy NGC1808, as observed by the XMM-Newton X-ray observatory. It proves the presence in this galaxy of heavy elements within a hot gaseous plasma (=highly ionised gas) that had been created in massive stars before being released into the interstellar medium (ISM) again via supernova explosions. The X-ray spectrum traces them in the hot ionised medium, which is one part of the ISM in galaxies.
Spectroscopic kinematical studies
Another typical application of astronomical spectroscopy is to study the detailed shape of one or more emission lines from an object and use this to determine the objects kinematical behaviour (i.e. how it moves). The Doppler shift of the line emission is used to determine at which location on the sky an object is moving at what speed with respect to the observer. Two examples are listed on the page about radio emission processes, in the section about the HI emission line.
Spectroscopy in cosmology
Based on the finding by E. Hubble that the Doppler shifts of emission (and/or absorption) lines of extragalactic objects are related to their distance from us (in an expanding Universe), a Doppler shift measurement can be used to measure distances. Together with the projected location of objects (mostly galaxies) on the sky, their three-dimensional distribution can be deduced and the current expansion rate of the Universe determined (by measuring the value of the "Hubble constant", H0).
Spectroscopical studies are conducted with spectrometers.