(CNN) Democratic presidential candidate Bernie Sanders is tying himself to former President Barack Obama in a new TV ad despite years of criticizing him and his administration.

While Sanders frequently praised many aspects of Obama-era policies and defended the then-President's agenda from what he said was an obstructionist Republican Party, a CNN KFile review of Sanders' comments during Obama's years in office shows the Vermont senator was also sharply critical of the President.

On at least four occasions, Sanders said it would be good for Obama to face a primary challenge while running for reelection in 2012. He challenged Obama from the left on discussions of cutting Social Security and Medicare . And he said Obama hadn't done enough on regulating Wall Street or improving healthcare. He also said Obama was wrong on trade policies.

"I think one of the reasons the President has been able to move so far to the right is that there is no primary opposition to him," said Sanders in a July 2011 radio interview. "And I think it would do this country a good deal of service if people started thinking about candidates out there to begin contrasting what is a progressive agenda as opposed to what Obama is doing."

The Sanders campaign noted he was far from Obama's only left wing critic, flagging that progressive groups like MoveOn and the Progressive Campaign Change Committee also challenged Obama from the left on issues. Mike Casca, a Sanders campaign spokesman, said the senator was proud to work with President Barack Obama.

"Bernie is proud of so many of the accomplishments of President Obama and his administration, which is why he fought hard to protect the Affordable Care Act and the Iran nuclear deal from Donald Trump's attacks," Casca told CNN in an email.

In the ad, Obama praised Sanders for having "the virtue of saying exactly what he believes. Great authenticity, great passion, and is fearless," though a transcript of the comments shows the ad omits Obama's admission that he didn't know Sanders as well since he didn't serve in his administration.

Obama also exclaimed, "Feel the Bern!" at the end of the ad, suggesting a possible endorsement from Obama. However, the exclamation was said at the 2016 Democratic National Convention in an effort to get Sanders' supporters to vote for Clinton. Obama has not endorsed anyone in the 2020 election

The ad now signals a new direction for the Sanders campaign as it seeks to stop Biden's momentum from clinching the Democratic nomination.

Even when defending Obama during his presidency, Sanders argued he wasn't a huge supporter of Obama.

Sanders, who worked with Obama on a host of issues, maintained that Obama was not a progressive , but instead a centrist in the Democratic Party. He said Obama hadn't stood up to extremism in the Republican Party.

"I think he's a pretty honest guy and the President as you may recall just a few weeks ago, said that if we were in the 1980s he would have been considered something like a moderate Republican," Sanders said on WNYC in 2013 after Obama had been elected to a second term. "And I think he's kind of a centrist somewhere in the middle of the Democratic Party. But no, I don't think he is a progressive."

"I was very disappointed in terms of his unwillingness to be more aggressive in standing up to what has increasingly become a right wing extremist Republican Party," Sanders added. "And he really hasn't, to my mind, done that effectively."

Speaking on CNN's "Crossfire" in 2013, Sanders' critiqued Obamacare, saying, though he voted for it, he wouldn't argue with someone who said it was too complicated.

"Let me be very clear," Sanders said. "I voted for Obamacare. But to be very honest with you, I'm not going to argue with anybody who says that it is too complicated. I am an advocate of a 'Medicare for All' single payer program. I think Obamacare is a good Republican Romney type program, which has worked in Massachusetts. It's a moderate program which addresses some needs."

One of Obama's biggest mistakes as president, Sanders said in September 2011, was abandoning his grassroots supporters and not following through on his campaign promises.

"In terms of Wall Street, in terms of the economy, in terms of taxes, terms of civil liberties, the President has clearly been disappointing to many people and nowhere near as strong as we had hoped that he would be," Sanders said.

"I believe he ran one of the greatest campaigns that I've ever seen in my lifetime. He inspired people, galvanized people, brought people together," he added. "But for whatever reasons, he has not followed through with a lot of the issues that he discussed in his campaign and I think has not stood up to the right wing extremism that is so potent in Washington right now. And the answer was what you're asking is what do we do? Well, the only thing that I know to do is to rally the American people around the progressive agenda."

This story has been updated with additional comment from the Sanders campaign.