我试图弄清楚如何从 ASP.NET 网站(使用 vb.NET)中使用 Microsoft Online Services Migration Toolkit PowerShell 命令。
我已经开始使用如何在 ASP.NET 中使用 PowerShell 的指南 - 从这里开始: http: //devinfra-us.blogspot.com/2011/02/using-powershell-20-from-aspnet-part-1 .html
我正在尝试研究如何实现 Online Services Migration Toolkit PowerShell cmdlet。
这是我的代码隐藏片段:
Sub GetUsers()
Dim iss As InitialSessionState = InitialSessionState.CreateDefault()
iss.ImportPSModule(New String() {"MSOnline"})
Using myRunSpace As Runspace = RunspaceFactory.CreateRunspace(iss)
myRunSpace.Open()
' Execute the Get-CsTrustedApplication cmdlet.
Using powershell As System.Management.Automation.PowerShell = System.Management.Automation.PowerShell.Create()
powershell.Runspace = myRunSpace
Dim connect As New Command("Get-MSOnlineUser -Enabled")
Dim secureString As New System.Security.SecureString()
Dim myPassword As String = "ThePassword"
For Each c As Char In myPassword
secureString.AppendChar(c)
Next
connect.Parameters.Add("Credential", New PSCredential("admin@thedomain.apac.microsoftonline.com", secureString))
powershell.Commands.AddCommand(connect)
Dim results As Collection(Of PSObject) = Nothing
Dim errors As Collection(Of ErrorRecord) = Nothing
results = powershell.Invoke()
errors = powershell.Streams.[Error].ReadAll()
For Each obj As PSObject In results
Response.Write(obj.Properties("Identity").Value.ToString())
Next
End Using
End Using
End Sub
当我尝试通过页面运行代码时,出现以下错误
术语“Get-MSOnlineUser -Enabled”未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确并重试。
所以我猜我还没有弄清楚如何导入在线服务迁移工具包 PowerShell CmdLets。我也不确定这条线是否:
iss.ImportPSModule(New String() {"MSOnline"})
完全正确。有没有办法可以验证模块名称?
我也不确定在哪里以及如何引用 .dll 文件。目前我已将它们复制到我的 bin 文件夹中,但我无法将它们添加为引用,那么 ImportPSModule 语句如何知道在哪里可以找到它们?特别是当网站发布到最终生产服务器时。
另一个问题,我应该使用 x86 还是 x64 cmdlet?我在 Win7 x64 上开发,但不确定网站是构建为 x86 还是 x64?我需要找出服务器是什么架构吗?