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 {
$ip6 = Get-NetAdapterBinding -InterfaceAlias $_ .Name -ComponentID ms_tcpip6
IF($ip6 .Enabled -eq $true ){
Disable-NetAdapterBinding -InterfaceAlias $_ .Name -ComponentID ms_tcpip6
IF($?){
Write-Output "Net Adapter [ $($_.Name) ] ms_tcpip6 was successfully disabled. "
}else {
Write-Output "Net Adapter [ $($_.Name) ] ms_tcpip6 was not disabled. "
}
}else {
Write-Output "Net Adapter [ $($_.Name) ] ms_tcpip6 already disabled. "
}
}
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