I have some files that I have to deliver to certain users and I need to handle this with powershell. My issue is that some of these users will be on terminal servers and I’ll have to loop through logged in users to ensure I’m reaching the correct users. My code block works perfectly when running from ISE but when running through PSADT (for mass deploy) it doesn’t do anything at all.
here’s my code block
## <Perform Installation tasks here>
$LoggedInUser = Get-LoggedOnUser | Select -ExpandProperty 'UserName'
$AD_Group = "AD Group"
$TargetURL = "https://url"
ForEach ($LoggedInUser in $LoggedInUsers)
{
$Path = "$Env:SystemDrive\Users\$LoggedInUser\Desktop\Dashboards\Dashboard.url"
$Fldr = ($Path | Split-Path)
If (([ADSISEARCHER]"samaccountname=$(($LoggedInUser))").Findone().Properties.memberof -replace '^CN=([^,]+).+$','$1' -ccontains $AD_Group)
{
New-Shortcut -Path $Path `
-TargetPath $TargetURL `
-Description 'Financial Dashboard'
}
}