I think the script just above you question does exactly that.
And for running PowerCLI scripts have a look at
I think the script just above you question does exactly that.
And for running PowerCLI scripts have a look at Execute PowerCLi scripts out of PowerCli Console?