I'm having trouble with the Compare-Object command within a function in my PowerShell script. When I run the line that sets $deletevars outside of the function, it works perfectly fine. However, inside the function, it returns nothing as if Compare-Object can't operate there. Here's a snippet of my function:
```powershell
Function clean-vars {
write-host "Sysvars = $sysvars"
$sessionvars = (get-variable).name
write-host "Sessionvars = $sessionvars"
$deletevars = compare-object -ReferenceObject $sessionvars -DifferenceObject $sysvars
write-host "Deletevars = $deletevars"
foreach ($var in $deletevars) {
if ($var.SideIndicator -eq "<=") {
Remove-Variable -Name $var.InputObject -ErrorAction SilentlyContinue
}
}
}
```
For this to work, $sysvars has to be set before running the script. I'm wondering why the Compare-Object command is not functioning as expected within the function's scope?
0 Answers
There is no answer to this question yet. If you know the answer or can offer some help, please use the form below.
Related Questions
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically
[Centos] Delete All Files And Folders That Contain a String