Strange behaviour in ISE

This topic contains 4 replies, has 2 voices, and was last updated by Profile photo of Erik Schliewe Erik Schliewe 8 months ago.

  • Author
    Posts
  • #36901
    Profile photo of Erik Schliewe
    Erik Schliewe
    Participant

    Hey folks,

    my colleague has written a script which queries the free disk space of a server via WMI.
    He runs it out of the ISE without any errors.

    The strange thing is, as long as the ISE is open, every minute there are logon and logoff events in the security log of the target server. This continues until he closes the ISE.

    When he closes the ISE, there are no events anymore.

    This also happens when he runs the WMI query separately in ISE.
    When he runs this script out of a console, it's all fine...no events.

    Any thoughts?

  • #36904
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    Depends on what's in his script, I imagine. Can't really guess without seeing it.

    However, I can tell you that when you use the ISE's "Run Script" option (or press F5), it's a lot like dot-sourcing a script at the console in powershell.exe. That's what allows you to inspect variables and their values after a script has finished running in the ISE. That's very likely going to be the cause of the difference in behavior that you're seeing.

  • #36907
    Profile photo of Erik Schliewe
    Erik Schliewe
    Participant

    Hi Dave,

    sorry, my bad.

    This is his script:


    #spaltenköpfe schreiben
    $Spaltenkopf = "hostname freeSpace"
    get-variable -Name Spaltenkopf | Select-object {$_.Value} | ft -hidetableheaders >D:\FreeSpaceC\Symantec.txt
    #Events abrufen
    $DRSServers = Get-content D:\FreeSpaceC\symatecsrv.txt
    #Abfrage Kommndo

    ForEach ($server in $DRSServers)
    {
    try
    {
    Get-Variable server >> D:\FreeSpaceC\Symantec.txt
    $result = Get-WMIObject Win32_LogicalDisk -computername $server -filter "name='c:'" | select name, freespace | ft -hidetableheaders -ea Stop
    $result >> D:\FreeSpaceC\Symantec.txt
    }
    catch [Exception]
    {
    if ($_.Exception.GetType().Name -eq "COMException")
    {
    "Der Server ist nicht erreichbar" >> D:\FreeSpaceC\Symantec.txt
    }
    }
    }
    (gc D:\FreeSpaceC\Symantec.txt) | Foreach {$_.TrimEnd()} | where {$_ -ne ""} | Set-Content D:\FreeSpaceC\Symantec.txt

  • #36909
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    That is odd. I don't see anything in that script which seems like it should be keeping any open connections. Maybe it's something that the WMI .NET objects do, and we never noticed.

    If you're running PowerShell v3 or later, you could try Get-CimInstance instead, and see if it behaves the same way.

  • #37546
    Profile photo of Erik Schliewe
    Erik Schliewe
    Participant

    Hi Dave,

    thanks for your hints. He re-designed his script and now this behaviour no longer occurs...honestly I don't know why...

    Cheers

You must be logged in to reply to this topic.