gpt4 book ai didi

mysql - 我可以通过 Azure 自动化中的 Runbook 将所有 Azure Active Directory 用户导出到 MySQL 数据库吗?

转载 作者:行者123 更新时间:2023-11-29 15:17:04 26 4
gpt4 key购买 nike

我可以通过 Azure 自动化中的 Runbook 将所有 Azure Active Directory 用户导出到 MySQL 数据库吗?有人拥有某种代码,例如仅包含用户的名字和姓氏吗?

最佳答案

是的,你可以。您的代码看起来像这样。

######## Connect to Azure AD ##################
# Get Azure Run As Connection Name
$connectionName = "AzureRunAsConnection"
# Get the Service Principal connection details for the Connection name
$servicePrincipalConnection = Get-AutomationConnection -Name $connectionName

# Logging in to Azure AD with Service Principal
"Logging in to Azure AD..."
Connect-AzureAD -TenantId $servicePrincipalConnection.TenantId `
-ApplicationId $servicePrincipalConnection.ApplicationId `
-CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint

######## Create CSV of all users ##################

$users = Get-AzureADUser -All $true
$userList = @()

foreach ($user in $users){
$userex = $user | Select-Object -ExpandProperty ExtensionProperty
$userProperties = [ordered] @{
accountEnabled=$user.GivenName
userPrincipalName=$user.Surname

}
$u = new-object PSObject -Property $userProperties
$userList += $u
}
$userList | Export-Csv .\users.csv -NoTypeInformation

$csvFullPath = Resolve-Path .\users.csv

######## Import CSV data into MySql ##################

[system.reflection.assembly]::LoadWithPartialName("MySql.Data")
$mysqlConn = New-Object -TypeName MySql.Data.MySqlClient.MySqlConnection
$mysqlConn.ConnectionString = "SERVER=localhost;DATABASE=loadfiletest;UID=root;PWD=pwd"
$mysqlConn.Open()
$MysqlQuery = New-Object -TypeName MySql.Data.MySqlClient.MySqlCommand
$MysqlQuery.Connection = $mysqlConn
$MysqlQuery.CommandText = "LOAD DATA LOCAL INFILE '$csvFullPath' INTO TABLE loadfiletest.testtable FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '""' LINES TERMINATED BY '\r\n' (GivenName, Surname)"
$MysqlQuery.ExecuteNonQuery()

关于mysql - 我可以通过 Azure 自动化中的 Runbook 将所有 Azure Active Directory 用户导出到 MySQL 数据库吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59632332/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com