Skip to main content
Solved

Log Quesiton

  • April 8, 2022
  • 1 reply
  • 117 views

daniel.newman
Forum|alt.badge.img

Is there a way to echo a command and make the status of a worklet visible?

 

Example; if I sent a PS command to a system lets say to unjust something. I would like to see something in the logs showing a status. 

Get-NetAdapter | foreach { Disable-NetAdapterBinding -InterfaceAlias $_.Name -ComponentID ms_tcpip6 }

Current log shows: 

1

nothing else.

Maybe something on how to echo the results or response from the command.

Best answer by jack.smith

@daniel.newman one way to get more output is to introduce some Boolean logic and add in the logging of choice based on what is being done. 

Get-NetAdapter | ForEach-Object {

    # Get Current State
    $ip6 = Get-NetAdapterBinding -InterfaceAlias $_.Name -ComponentID ms_tcpip6

    # React to Current State
    IF($ip6.Enabled -eq $true){

        # Disable
        Disable-NetAdapterBinding -InterfaceAlias $_.Name -ComponentID ms_tcpip6

        # Check Status of Disabling
        IF($?){ 
            Write-Output "Net Adapter [ $($_.Name) ] ms_tcpip6 was successfully disabled. "
        }else{
            Write-Output "Net Adapter [ $($_.Name) ] ms_tcpip6 was not disabled. "
        }

    }else{
        # Disabled
        Write-Output "Net Adapter [ $($_.Name) ] ms_tcpip6 already disabled. "
    }

} # end ForEach

Using $? in powershell is pretty cool. I’d check out Automatic Variables here --

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_automatic_variables?view=powershell-7.2

View original
How helpful was this post to you?

1 reply

jack.smith
Forum|alt.badge.img+1
  • All Star
  • 168 replies
  • Answer
  • April 12, 2022

@daniel.newman one way to get more output is to introduce some Boolean logic and add in the logging of choice based on what is being done. 

Get-NetAdapter | ForEach-Object {

    # Get Current State
    $ip6 = Get-NetAdapterBinding -InterfaceAlias $_.Name -ComponentID ms_tcpip6

    # React to Current State
    IF($ip6.Enabled -eq $true){

        # Disable
        Disable-NetAdapterBinding -InterfaceAlias $_.Name -ComponentID ms_tcpip6

        # Check Status of Disabling
        IF($?){ 
            Write-Output "Net Adapter [ $($_.Name) ] ms_tcpip6 was successfully disabled. "
        }else{
            Write-Output "Net Adapter [ $($_.Name) ] ms_tcpip6 was not disabled. "
        }

    }else{
        # Disabled
        Write-Output "Net Adapter [ $($_.Name) ] ms_tcpip6 already disabled. "
    }

} # end ForEach

Using $? in powershell is pretty cool. I’d check out Automatic Variables here --

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_automatic_variables?view=powershell-7.2


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings