The state's publicly owned electricity companies spent nearly $5 million in four years on private investigators and external law firms to investigate their own workers over alleged disciplinary and industrial indiscretions, new figures reveal.

The figures, obtained by the Electrical Trades Union and the United Services Union under freedom, show that the three largest state-run providers – Endeavour Energy, AusGrid and Essential Energy – spent $4,604,703 on external legal services alone between 2010 and 2014.

The majority of this – $4,153,837 – was spent on "industrial matters" while the remainder was spent on investigations into disciplinary matters, including $389,387 on private investigators.

Networks NSW, which represents the three electricity providers, said it was necessary to hire external investigators to investigate code of conduct breaches and pre-employment checks, describing them as a "legitimate cost of business".

But the unions said it was outrageous that the providers were using public money from electricity consumers to pay for attacks on workers, including spying on them.