'connect-msolservice' 용어가 cmdlet, 함수, 스크립트 파일 또는 실행할 수 있는 프로그램 이름으로 인식되지 않습니다. 이름이 정확한지 확인하고 경로가 포함된 경우 경로가 올바른지 검증한 다음 다시 시도하십시오.
오류가 발생하였습니다.
개발환경의 문제로 파워셀 폴더를 복사하여 주면 처리가 된다.
Crazy stuff, this PowerShell.
I was doing a C# program that needed to load in a PowerShell module with cmdlets intended for Office365. Even I had installed the x64 version of this module; it never showed up the proper place on the hard disk meaning my program failed to load it. Driven by a post on a forum somewhere on the WWW; I tried the following trick which actually worked to my surprise.
I’m running a x64 OS currently (Win8 Pro).
Copy the folder MSOnline from (1) –> (2) as seen here
1) C:\Windows\System32\WindowsPowerShell\v1.0\Modules\(MSOnline)
2) C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Modules\(MSOnline)
After doing this trick, your x64 bit OS will happily load-in the MSOnline PS module into your runspace in your C# program.
var iniSS = InitialSessionState.CreateDefault();
iniSS.ImportPSModule(new[] { "MSOnline" });
var rs = RunspaceFactory.CreateRunspace(iniSS);
rs.Open();
m_PowerShell = PowerShell.Create();
m_PowerShell.Runspace = rs;
//credentials
SecureString ss = m_PowerShellPwd.ConvertToSecureString();
var connectCmd = new Command("Connect-MsolService");
connectCmd.Parameters.Add("Credential", new PSCredential (m_PowerShellUsr, ss));
//add to ps
m_PowerShell.Commands.Clear();
m_PowerShell.Streams.Error.Clear();
m_PowerShell.Commands.AddCommand(connectCmd);
//connect
m_PowerShell.Invoke();
var err = m_PowerShell.Streams.Error.ReadAll();
참고사이트 :
http://blog.clauskonrad.net/2013/06/powershell-and-c-cant-load-msonline.html