Powershell snippets
I first used the following to get the list:
Get-Content Computers.txt | ./Get-ScheduledTask.ps1
This gave me the output, using the servers in the Computers.txt file, but not in a CSV format. The following is what I came up with next:
Get-Content Computers.txt | ./Get-ScheduledTask.ps1 | Export-Csv schtask.csv
This gave me the output, using the servers in the Computers.txt file, and it was in a CSV format
Getting the status of all services on this computer:
get-service
Getting a list of running services on this computer:
Get-Service | Where-Object {$_.status -eq "running"}
Getting the status of a specific service:
Get-Service | Where-Object {$_.name -eq "WINS"}
getting the status of a specific service on a remote computer
Get-Service -computername SDRIPS01 | Where-Object {$_.name -eq "WINS"}
Now for a list of servers. this one provides lots of info
get-content servers.txt | % { if ($s=get-service -computer $_ -name WINS -ErrorAction SilentlyContinue) { $s | select * } else {"Service WINS is not avaible on $_"} }
list of servers. this one provides less info
get-content servers.txt | % { if ($s=get-service -computer $_ -name WINS -ErrorAction SilentlyContinue) { $s | select MachineName, ServiceName, Status } else {"Service WINS is not avaible on $_"} }
I wanted to expand my search, but this was too wide
Get-ADComputer -Filter * | Select -Expand Name
I tried this
Get-ADComputer -Filter { OperatingSystem -Like '*Windows Server*' } -Properties OperatingSystem | Select Name, OperatingSystem | Format-Table -AutoSize
But I went with this:
Get-ADComputer -Filter { OperatingSystem -Like '*Windows Server*' } -Properties OperatingSystem | Select -Expand Name
this will get the network info from a number of servers, based on a list.
get-wmiobject -query "Select * FROM Win32_NetworkAdapterConfiguration WHERE IpEnabled='TRUE'" -computer (get-content IPS-Servers.txt) | ft __SERVER,IPAddress,DNSServerSearchOrder,WINSPrimaryServer,WINSSecondaryServer -auto
Hold onto this one, output to csv
get-wmiobject -query "Select * FROM Win32_NetworkAdapterConfiguration WHERE IpEnabled='TRUE'" -computer (get-content TX-Servers-hq.txt) -ErrorAction SilentlyContinue | select-object -Property __SERVER,{$_.IPAddress},{$_.DNSServerSearchOrder},WINSPrimaryServer,WINSSecondaryServer | export-csv tx-hq-dns-wins.txt
this worked pretty well too
####################################################################### # Author : Matthew C. Huntley # Original Source: Chethan Gatty # This PS script provides Network Interface Information from a list of computers. ####################################################################### $names = Get-Content "C:\Users\N900338\powershell\machinelist.txt" @( foreach ($name in $names) { if ( Test-Connection -ComputerName $name -Count 1 -ErrorAction SilentlyContinue ) { $wmi = gwmi -query "Select * FROM Win32_NetworkAdapterConfiguration WHERE IpEnabled='TRUE'" -computer $name | select-object -Property __SERVER,@{n='IPAddress';e={ "$($_.IPAddress)" }}, @{n='DNSServers';e={ "$($_.DnsServerSearchOrder)" }},WINSPrimaryServer,WINSSecondaryServer Write-output "$name, $wmi " } else { Write-output "$name is not pinging" } } ) | Out-file -FilePath "C:\Users\N900338\powershell\GetNetworkInfo-results.txt"
this was derived from:
####################################################################### # Author : Chethan Gatty # This PS script provides Uptime and Pingstatus for list of computers. ####################################################################### $names = Get-Content "C:\Users\N900338\powershell\machinelist.txt" @( foreach ($name in $names) { if ( Test-Connection -ComputerName $name -Count 1 -ErrorAction SilentlyContinue ) { $wmi = gwmi -class Win32_OperatingSystem -computer $name $LBTime = $wmi.ConvertToDateTime($wmi.Lastbootuptime) [TimeSpan]$uptime = New-TimeSpan $LBTime $(get-date) Write-output "$name Uptime is $($uptime.days) Days $($uptime.hours) Hours $($uptime.minutes) Minutes $($uptime.seconds) Seconds" } else { Write-output "$name is not pinging" } } ) | Out-file -FilePath "C:\Users\N900338\powershell\results.txt"
Tracking AV Versions:
Interesting articles
Ok, trying another tack at this:
Get a list of all the servers:
Get-ADComputer -Filter {OperatingSystem -Like "Windows Server*"} -Property * | Format-Table Name,OperatingSystem,OperatingSystemServicePack -Wrap -Auto
Get the list of network profiles on the system.
Get-NetConnectionProfile Change the network interface to private, use the network interface index number from the previous command.
Set-NetConnectionProfile -InterfaceIndex 10 -NetworkCategory Private