Solved

Log Quesiton

  • 8 April 2022
  • 1 reply
  • 40 views

Userlevel 1
Badge

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.

icon

Best answer by jack.smith 12 April 2022, 02:28

View original

1 reply

Userlevel 4
Badge

@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