简体   繁体   English

从 Windows 表单/WPF 访问 PowerShell 的 office 365 身份验证弹出窗口

[英]Access office 365 authentication popup of PowerShell from Windows Form/WPF

I have a following PowerShell script, this scripts connects to my Azure Analysis services.我有以下 PowerShell 脚本,该脚本连接到我的 Azure 分析服务。 As I execute following script, it opens a popup like image below.当我执行以下脚本时,它会打开一个如下图所示的弹出窗口。

param(
    [String]
    $envName1
)

$loadInfo1 = [Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices")
$server1 = New-Object Microsoft.AnalysisServices.Server
$server1.Connect($envName1)
return $server1

在此处输入图像描述

Problem is that I want to execute this PowerShell from my WPF application.问题是我想从我的 WPF 应用程序中执行这个 PowerShell。 I don't understand, how can I access this Popup in my WPF application.我不明白,如何在我的 WPF 应用程序中访问此弹出窗口。

I'm not too sure what you mean by that.我不太清楚你的意思。 However, you need an account to connect to Azure, maybe you signed out or never actually signed in to Visual Studio.但是,您需要一个帐户才能连接到 Azure,也许您已退出或从未真正登录到 Visual Studio。

Edit: I finally understand what you mean (slightly).编辑:我终于明白你的意思了(稍微)。 So there are basically two solutions.所以基本上有两种解决方案。 First one is Azure AD.第一个是 Azure AD。 To connect to Office 355 with PowerShell using the AzureAD module, you'll first need to install it.要使用 AzureAD 模块通过 PowerShell 连接到 Office 355,首先需要安装它。 You can do so by running Install-Module AzureAD from an administrative PowerShell session.您可以通过从管理 PowerShell session 运行安装模块 AzureAD 来执行此操作。 Once you have the module installed, run the Connect-AzureAD cmdlet.安装模块后,运行 Connect-AzureAD cmdlet。 Once you do, PowerShell will prompt for your Microsoft ID and password (Work or school account).完成后,PowerShell 将提示您输入 Microsoft ID 和密码(工作或学校帐户)。 Once authenticated, you'll be able to use all of the commands in the module.通过身份验证后,您将能够使用模块中的所有命令。

Connecting to Office 365 with the MSOnline Module: Connecting to Office 365 with PowerShell using the MSOnline module requires a little bit more effort.使用 MSOnline 模块连接到 Office 365:使用 MSOnline 模块通过 PowerShell 连接到 Office 365 需要更多的努力。 Assuming you have the Microsoft Online Services Sign-In Assistant for IT Professionals RTW software package installed:假设您已安装 Microsoft Online Services Sign-In Assistant for IT Professionals RTW 软件 package:

Install the MSOnline module from the PowerShell Gallery by running from an administrative PowerShell console:通过从管理 PowerShell 控制台运行从 PowerShell 库安装 MSOnline 模块:

Install-Module MSOnline (Function)安装模块 MSOnline(功能)

Once the module is installed, run Get-Module to ensure PowerShell can find the module.安装模块后,运行 Get-Module 以确保 PowerShell 可以找到该模块。

在此处输入图像描述

Finally, run the Connect-MsolService cmdlet to authenticate to Azure AD.最后,运行 Connect-MsolService cmdlet 对 Azure AD 进行身份验证。 This will prompt you for your Office 365 credential.这将提示您输入 Office 365 凭据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM