所以這個腳本應該檢查用戶的成員資格并配置 odbc 連接,如果他們是組的一部分。這在我的 azure 設備上完美運行,但我安裝了廣告工具。我想使用 Intune 將其推到 azure 筆記本電腦。但它在設備上給了我一個錯誤:
Get-ADGroupMember : The term 'Get-ADGroupMember' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name,
or if a path was included, verify that the path is correct and try again.
At line:16 char:20
$members = Get-ADGroupMember -server pitt-drdc-01.univ.pitt.e ...
~~~~~~~~~~~~~~~~~
CategoryInfo : ObjectNotFound: (Get-ADGroupMember:String) [],
CommandNotFoundException
FullyQualifiedErrorId : CommandNotFoundException
ps 我很討厭這個,如果有幫助的話,這些將在 azure 注冊的設備上運行。
###########################################################################################
# Createing ODBC Connection to FMTMA-BE02 for Jobs
###########################################################################################
$ChkFile = "C:\Windows\System32\msodbcsql17.dll"
$FileExists = Test-Path $ChkFile
If ($FileExists -eq $True) {
# Configure Odbc connection for FMTMA-BE02
$user = "$env:UserName"
$groups = 'CN=FM-TMASQLUserAccess'
#verify Group Membership
foreach ($group in $groups) {
$members = Get-ADGroupMember -server fsc-server-place.com -Identity $group -
Recursive | Select -ExpandProperty SamAccountName
# If users in in Ad group Create ODBC connection.
If ($members -contains $user) {
Write-Host "Adding ODBC Connection FMTMA-BE02"
Add-OdbcDsn -DriverName "ODBC Driver 17 for SQL Server" -DsnType User -Name fmTMA-BE02
-AsJob -SetPropertyValue ("Server=FSC-TMA-BE02.edu", "Trusted_Connection=Yes",
"Database=FM")
}
Else {
Write-Host "$user is not a member of $group"
}
}
}
else {
Write-Host "$user is not a member of $group"
}
uj5u.com熱心網友回復:
又快又臟:
$Group = [ADSI]"CN=ODBCGroup,OU=Admin Groups,DC=Domain,DC=com"
if ($userDistinguishedName -match $Group.Member) {
# do stuff
}
您可以對組成員進行部分匹配,但請記住它們是 distinctNames - 在我的環境中,如果我們嘗試匹配$env:username,它會失敗。
或者,如果您的組很大和/或您有很多網路延遲,另一種方法是在本地計算機上實際檢查用戶的組成員身份,而不是決議您從中拖出的所有組成員廣告。
您可以打開用戶的 Kerberos 令牌以列出他們的 AD 組成員身份 [System.Security.Principal.WindowsIdentity]::GetCurrent()
然后,您可以將組的 SID 嵌入到腳本中以與令牌的組串列匹配,或者您可以通過檢查 ADSI 中的組 SID 來驗證它。
$krbToken = [System.Security.Principal.WindowsIdentity]::GetCurrent()
# get group SID - you can use [adsisearcher] with an LDAP query if
# you don't want to embed the group DN (e.g. for use in multiple domains)
$odbcSID = ([ADSI]("LDAP://CN=ODBCGroup,OU=Admin Groups,DC=Domain,DC=com")).objectSid.value
# convert to string for matching
$strOdbcSID = (New-Object System.Security.Principal.SecurityIdentifier($odbcSID,0)).Value
# $krbToken.Groups is a hashtable with lots and lots of domain and group SIDs
If ($krbToken.Groups.value -match $strOdbcSID) {
# Do stuff
}
這是一篇出色的文章,它演示了這種通過 Kerberos 令牌檢查組 SID 的方法 - 由于我們有一個已知組,因此場景稍微簡單一些:https : //activedirectoryfaq.com/2016/08/read-kerberos-token-電源外殼/
值得嘗試使用 a 的兩個選項,Measure-Command以查看在您的場景中哪個可能更有效。
uj5u.com熱心網友回復:
問題是你真正需要什么。使用 PS 模塊可能是最簡單的。您也可以為此使用遠程會話(取決于這些筆記本可以做什么以及它們獲得的訪問權限)。
就我從您的代碼中看到的而言,您真的只對某個人是特定組的成員時感興趣。根據您的操作,您可以對用戶本身使用 LDAP 查詢,而不是抓取這些組的每個用戶來執行此操作。
還有其他工具也可以幫助您,例如whoami /groups。另一種選擇可能是使用net user username /DOMAIN. whoami從 PS使用非常容易。
$lookupGroups = @("FM-TMASQLUserAccess")
$groups = whoami /groups /fo csv | ConvertFrom-Csv
$groups | Where-Object {$_.'Group Name' -in $lookupGroups} | ForEach-Object {Add-ODBC}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/316435.html
標籤:电源外壳
下一篇:替換JSON檔案中的值
