The H1B is a mixed bag. On one hand it's abused by a lot of these foreign tech companies, mostly from India, that are just basically staffing mills for cheap IT employees that undercut American labor, and whom most of them have never even step foot in this country.
On the other hand it's a great tool to retain high quality talent who have studied in the US, and provides a path to green card and citizenship. These people are usually the creme de la creme of their native countries who have come to attend the top American institutes, and many do want to live in this country and contribute. In a time where intellectual property is a valuable resource, and the brain drain is a real thing, the H1B visa helps overcome that.
Unfortunately the H1B visa system is deeply flawed. It's a lottery system where the odds are the same for a PH.D student who have studied and worked as interns in the US for years versus some cheap Indian IT guy who's never been in this country and will be getting paid much less than market value. I've seen cases where very good co-workers did not win the H1B lottery and had to go back to their home countries, despite being in the US for 6+ years, working for an American company under the F1 OPT visa for two years and paying taxes. Due to the uncertainty and cost of the H1B visa a lot of companies don't actually sponsor the candidates, further restricting the employment prospects of quality candidates from the American post graduate education system.
What really needs to happen is a total revamp of the H1B system. There needs to be a faster, more secure and less restrictive visa category for people who have studied in the country, worked here and paid taxes, rather than lumping them with the low wage foreign IT sweatshop workers. In times like this where China is investing billions to attract top quality professors and researchers to work for China, we need to really find a way to attract and retain high quality foreigners who want to live in this country and contribute to its future success.