Hi Mike,
To pass a value to a variable outside the function the scope must be specified. Please see if this works for you.
function RemoveSvcAccount
{
$Terminalusers2 = [System.collections.arraylist]$Script:Terminalusers
foreach($svcAccount in $script:svcmap){
foreach($terminaluser in $Script:TerminalUsers){
if($terminaluser.samaccountname -eq $svcaccount.serviceaccountname)
{
$Terminalusers2.remove($terminaluser)
}
}
}
$Terminalusers2 | Out-File users1.txt
}
RemoveSvcAccount
Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.