Why Join
Become a member
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
C# Corner Home
Technologies
MonthlyLeaders
ASK A QUESTION
Forumguidelines
jesper
1.9k
89
44.9k
Powershell, help with incrementing inside foreach and scriptblock
Oct 17 2020 6:03 PM
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++
}
}
}
Reply
Answers (
8
)
having a problem with ZK SDK download -cannot get the whole log file
issue with Hybrid Exchange 2010 To Hybrid Exchange 2016