Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Putting two scripts together

$
0
0

I have a script that will Ping a machine and report if it is online or offline code below:

<#
Title: Ping-Test
Author: William H. Davis
Created: 5-May-2014
Synopsis: This script will ping a remote machine by name or IP "Your choice" and advise you if the machine is online
or offline. Keep in mind that this is the "Layer 1 Process" of the OSI Model.
#>

# Clear the screen
Clear-Host

# Variable to hold user input
$StrComputer = Read-Host 'Enter the computer name'

# Variable to hold/store the results of the "Test-Connection" call to determine the machines "Ping" status
$strTC = Test-Connection -ComputerName $StrComputer -count 1 -quiet

# IF statement to determine if the machine is online, or offline so as to inform the script user.
if($strTC-eq 'True') {write-host 'This machine is online'}


# if($strTC) {write-host 'This machine is online'}
else{Write-Host 'That machine is offline'}

Then I have another script that will report the logged on user code is below:

<#
Title: Get-LoggedOnUsernamePSStyle
Author: William H. Davis
Date: 6 June 2014
Synopsis: Queries a remote machine for the currently logged on user.
#>

# Clear the screen
Clear-Host

# Variable to hold user input
$Computer = Read-Host 'Enter the computer name'



(Get-WmiObject -Class Win32_ComputerSystem -ComputerName $Computer).username

Problem: I work in a corporate environment and our images are setup to use :Bitlocker" encryption. As most of you know, when SA's push patches/updates, it will sometimes require a reboot ending up in a situation where we have a machine that passes the ping test, and if it is booted into Windows it will show me the logged on user. I would like to be able to combine this script to have one that first reports the ping status, then if it passes the ping tells me if someone is or is not logged onto that machine. If we get 50 machines that pass the ping test and only 20 pass the logged on user test then it would tells us that 30 machines are either off or stuck at the bitlocker screen.

I am really trying hard to learn to do this myself, thanks to whom ever reads this and all the help I can get.


Viewing all articles
Browse latest Browse all 6937

Trending Articles