Hi,
I hope someone can spot the error:
This is a small function inside a bigger script.
I want it to increment $i everytime it iterate the foreach, but i cant get it to work. If i run only the line where $i++ is present, it will increment.
The message arriving to the users, so it works fine, its just ignoring the $i++
$i = 0
function Message {
start-job -Name Col01 -InitializationScript{Import-Module RemoteDesktop} -ScriptBlock{$Users = Get-RDUserSession -ConnectionBroker $ActiveConnectionBroker -CollectionName "col01"
foreach ($User in $Users) {
Send-RDUserMessage -UnifiedSessionID $User.UnifiedSessionId -HostServer $User.HostServer -MessageTitle "Info" -MessageBody $using:message
$i++
}
}
}

jesper89 reputationPosted Oct 18, 2020, 6:51 AM EDT
Varun SetiaRank #308 · 8.2K reputationPosted Oct 18, 2020, 9:02 PM EDT
jesper89 reputationPosted Oct 19, 2020, 6:49 AM EDT
Varun SetiaRank #308 · 8.2K reputationPosted Oct 21, 2020, 8:36 PM EDT
jesper89 reputationPosted Oct 23, 2020, 1:22 PM EDT
Varun SetiaRank #308 · 8.2K reputationPosted Oct 18, 2020, 6:23 AM EDT
Varun SetiaRank #308 · 8.2K reputationPosted Oct 23, 2020, 8:03 PM EDT
Varun SetiaRank #308 · 8.2K reputationPosted Oct 19, 2020, 7:33 AM EDT