The Attorney General is the legal adviser of each department in all matters relating to the department and to the powers and duties of its officers. Upon request of the head of a department, the Attorney General, or under his direction, the district attorney of any county in which the proceeding is brought, shall aid in any investigation, hearing, prosecution or trial had under the laws which the department is required to administer, and shall institute and prosecute all necessary actions or proceedings for the enforcement of such law and for the punishment of all violations thereof.