Skip to content

Instantly share code, notes, and snippets.

@darzo27
Last active February 22, 2018 08:29
Show Gist options
  • Save darzo27/6ff36378626491810591f3d166eef785 to your computer and use it in GitHub Desktop.
Save darzo27/6ff36378626491810591f3d166eef785 to your computer and use it in GitHub Desktop.
Get-Process | Group-Object ProcessName | ForEach-Object {
$_ | Select-Object -ExpandProperty Group | Select-Object -First 5
}
__________________________________________
Get-ADComputer -Filter * | foreach-object {
$Computer = $_.Name
$Running = Get-Service -Name "Bonjour Service" -ComputerName $Computer
If( $Running.Status -eq "Running" ) {
$ServiceStatus = "Running"
Write-Host "$Computer `t `t $ServiceStatus" -ForeGroundColor Green
}ElseIf ( $Running.Status -eq "Stopped" ) {
$ServiceStatus = "Not Running"
Write-Host "$Computer `t `t `t $ServiceStatus" -ForeGroundColor Yellow
}Else {
$ServiceStatus = "Not Installed"
Write-Host "$Computer `t `t $ServiceStatus" -ForeGroundColor Red
}
}
=========================================================================================
Output to csv
Get-ADComputer -Filter * | foreach-object {
$Computer = $_.Name
If(Test-Connection -Cn $Computer -BufferSize 16 -Count 1 -ea 0 -quiet){
$Running = Get-Service -Name "Bonjour Service" -ComputerName $Computer
If( $Running.Status -eq "Running" ) {
$ServiceStatus = "Running"
}ElseIf ( $Running.Status -eq "Stopped" ) {
$ServiceStatus = "Not Running"
}Else {
$ServiceStatus = "Not Installed"
}
}Else{
$ServiceStatus = "Machine Offline"
}
$obj = New-Object PSCustomObject -Property @{
"ComputerName" = $Computer
"Service Status" = $ServiceStatus
}
$obj | Export-Csv C:\bonjour.csv -Append -NoTypeInformation
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment