Jump to content

Rasmus Tved

Members
  • Posts

    3
  • Joined

  • Last visited

Posts posted by Rasmus Tved

  1. I have created this small script to enable monitoring of the active network adapter on a given machine. Hope this can be of some help for others in the forum. 

    $activeadapter = Get-NetAdapter | Where-Object {$_.status -EQ "UP" -and $_.HardwareInterface -and $_.Name -notlike "*npcap*"} | select DeviceID
    $DeviceID = $activeadapter.DeviceID
    
    Set-ItemProperty "HKLM:\SOFTWARE\MMSOFT Design\PC Monitor\NetworkInterfaces\" -Name count -Value 1
    Set-ItemProperty "HKLM:\SOFTWARE\MMSOFT Design\PC Monitor\NetworkInterfaces\" -Name service0 -Value "$DeviceID"

     

  2. Hi,

    I have expanded a bit on this small script, both to do some error handeling and do some logging of changes made.

    I have this running on my instace multiple times a day. Hope this can help someone. 

    #Check if eventlog source is already created, if not then create
    if (![System.Diagnostics.EventLog]::SourceExists("Pulseway Scripting")){
        New-EventLog -LogName Application -Source "Pulseway Scripting"
    }
    
    #Set username to blank
    $username = ''
    #Set username to actual username
    $username = $(Get-WMIObject -class Win32_ComputerSystem | select username).username 
    $usernamev2 = (((query user)[1]).TrimStart()).SubString(0,21)
    
    #Combine username and text
    $usertext = "| $username"
    
    #Fall back to alternative user information if first is empty
    if($usertext -eq "| ") {
    
    $usertext = "| $usernamev2"
    
    }
    
    #Collect current value
    $curvalue = $(Get-ItemProperty "HKLM:\SOFTWARE\MMSOFT Design\PC Monitor\" -Name ComputerName).Computername
    
    #Check that there is a username
    If ($usertext -ne "| ") {
        
        #Collect computername
        $computername = $env:COMPUTERNAME 
    
        #Combine username and text
        $pulsewayname = "$computername $usertext"
    
    
        #Check that current value is not the same as the new one
        if ($curvalue -ne $pulsewayname) {
            
            #Set the new value
            Set-ItemProperty "HKLM:\SOFTWARE\MMSOFT Design\PC Monitor\" -Name ComputerName -Value $pulsewayname
    
            #Write the changes to event log
            Write-EventLog -LogName Application -Source "Pulseway Scripting" -EventId 1000 -EntryType Information -Message `
            "Event: Pulseway Computername Updated
            Current user: $username
            Computername: $computername
            Changed from: $curvalue
            Changed to: $pulsewayname
            "
        }
    }

     

×
×
  • Create New...