Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Param (
- [Parameter(Mandatory = $true)][String]$InputFile, #This is where the .csv file is stored
- [Parameter(Mandatory = $true)][String]$OutputFile #This is where the results file will appear.
- )
- #Variables
- $ComputerName = Get-Content $InputFile -ErrorAction SilentlyContinue
- ###Enter Tasks Below as Remarks###
- #Test if the input file exists.
- if (Test-Path -path $InputFile) {
- #If the file exists continue.
- #Run the ForEach command, display each one and write to a file.
- Write-Host "-------------------------------------"
- Write-Host "-------------------------------------"
- Write-Host "-------------------------------------"
- foreach ($Computer in $ComputerName) {
- if (Test-Connection -ComputerName $Computer -Count 2 -Quiet) {
- Try {
- Write-Host -ForegroundColor Magenta "Scanning $Computer..."
- Invoke-Command -ComputerName $Computer -ScriptBlock {
- Get-WmiObject Win32_Service | Where-Object { $_.Name -like '*CWGMonitor*' } } -ErrorAction SilentlyContinue | #This line can be amended to check for anything required.
- Select-Object PSComputerName |
- Tee-Object -FilePath $OutputFile -Append
- }
- Catch {
- Write-Warning "Unable to access service information from $Computer"
- }
- }
- else {
- Write-Warning "Unable to ping $Computer"
- #Display when the script is complete.
- Write-Host -ForegroundColor Yellow "The Script is complete, the file has been stored here: $Outputfile"
- }
- #If the file doesnt exist display a message and exit the script.
- }
- }
- else {
- Write-Host -ForegroundColor Red "Unable to locate file at location - $InputFile"
- Write-Host -ForegroundColor Red "Now ending script"
- Return
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement