Lots of advice and allot of varying opinions. I've worked as a contractor in California and Texas, but only in a few counties in each state. The difference between the two is huge, so I would imagine that it's going to be like that all over the country. Regardless of what it is where you live, the only thing that matters is where the barn in question is located.
If it was built without permits and is not up to code, you can admit it and see what happens. I've been through this in CA, and the client was told to tear down the illegal building that he built. I wasn't licensed there, but worked on the side to help people out and make a buck for myself. In this case, there was only a few things wrong with the building to bring it up to code, and a big problem with it's setback. I suggested that he fight it after bringing it up to code. He was told that he had to tear it down and that there was no other option, but after talking to the commisioners, not the inspector, he was told that if he could get a varience to the law if he met code and had every neighbor in a radius to sign a letter stating that they would not complain about the building being built on the property line. I forget the distance, but he went out every night and got every single home in the radius to sign the petetion. He then went in front of the commision and was granted the variance to allow the building to remain where it was. He passed the inspection and it became a legal building. It took several months to get it all worked out, and a few weekends of my time to make the changes to the building, but in the end, he made it happen.
Another client of mine was one of those guys who really went out of his way to mess with city hall. It really didn't matter what it was, he just liked to challenge them. He even ran for office, but just on paper. He never raised any money or campagned, he just entered the race and pointed out everything that he didn't like about those in office. His favorite game, or at least to me it seemed that way, was to build something and get in trouble for it. Then he'd fight them by explaining that it had always been there, but he had just fixed it up, or remodeled it. He even did this with a pond on some land he owned, but build without a permit where you had to have a permit. He had dozers in there taking out trees and buildng the dam. They brought out arial pictures to show that there was never a pond there, and he said that there was and it had been dry for decades. Claimed that the dam was washed out, but before that, it had held water and was grandfathered in before their laws were passed about ponds and dams. He was lying through his teeth, having a great time with it, and in the end, he won his case.
Where I live now, code is by the city you are working in. If outside the city, then the state has code for contractors doing work for paying clients. If the homeowner is doing their own work, then there is no permit process, code inforcement or inspection. There is also a $10,000 threshold on when a permit is required for work. If I do a remodel that is under ten grand outside of city limits, no permit is needed.
The original poster needs to find out what the law is, what the status is on his building and what is required to brind power to it. The actual process of running the wire and making it happen is extremly simple. Figuring out if it's legal and if he wants to follow those laws is where it gets interesting. Does the code apply to the homeowner doing their own work? Or is there a way to have it grandfathered in to the existing building or home? Will the power company even ask for a permit or just install power to the meter? Here in Texas, you just call the power company and tell them what you want, then wait for them to show up and do the work. Most of the time they are so easy going that they will help out or make it right if you get it wrong. My brother just went through this at a house he just bought, but didn't have power to where he wanted it. I won't tell what he offered them, but they took out all the branches and old lines for him to get it done when they didn't have to. Sometimes a kind word and a little sugar will go a long ways when trying to get something done.
Whatever you do, make sure it's to code anyways. There is a very good reason for the rules in the code book and by following those rules, it will be done right without any concerns for safety. Every time that I've come across a disaster or failure in a home, it's because somebody didn't do it to code and took a shortcut. I've seen homes burned down and rooms gutted by fires because of a shortcut that would have cost less then ten dollars to do it right.
Good luck,
Eddie