So this script is supposed to check the user's membership and configure the odbc connection if they are part of the group.This runs flawlessly on my azure device but I have ad tools installed. I want to push this down using intune to azure laptops. But it gives me an error on the device:
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 I suck at this and these will run on azure enrolled devices if that helps.
###########################################################################################
# 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"
}