You know....the answer for this has been in my possession all along, in a
snippet someone emailed to me for inclusion in my "configuration library"
online.

The point I've been missing, Homer Simpson style, is that I was looking to
verify that the endpoint is connected to "any" network - when in fact if
they are wanting to copy files and folders, etc., surely that indicates
they need to verify that they are on the "corporate" network....massive
facepalm just hit me :-(

So all I need to do is leverage the bit of PS I was sent and change it to
my own requirements. I think this checks to see if a physical NIC is
connected and if it can connect to a DC, and then writes the results to a
log....shouldn't be too hard to adapt...

Thanks for the discussion which certainly made me think things thru
properly :-)

function writeevent() {
if ($args[0] -eq "-h") {
    Write-Host "usage: writeevent <event source> <event
type:Information,Warning,Error <event id> > <event text>"
    break
}
#count the arguments
if ($args.count -lt 4)
{
    write-host "Error calling writeevent. Too few arguments. use option -h
to see help" -foregroundcolor "red"
    break
}
trap
{ # this installs an error handler for the function
    write-host "Error writing to eventlog:" $_.Exception.GetType().FullName
+ $_.Exception.Message
    continue; # exiting a trap with "continue" says to continue on the next
line of the script
}

$source = $args[0]
$type = $args[1]
$eventid = $args[2]
$msg = $args[3]
#Create the source, if it does not already exist.
if(![System.Diagnostics.EventLog]::SourceExists($source))
{
    [System.Diagnostics.EventLog]::CreateEventSource($source,'Application')
     $logfile = 'Application'
}
else
{
    $logfile =
[System.Diagnostics.EventLog]::LogNameFromSourceName($source,'.')
     #write-host "Source exists and is registered in the $logfile Log"
}
 #Check if Event Type is correct
       switch ($type)
       {
          "Information" {}
          "Warning" {}
          "Error" {}
          default {"Event type is invalid";exit}
       }
       $log = New-Object System.Diagnostics.EventLog
       $log.set_log($logfile)
       $log.set_source($source)
       $log.WriteEntry($msg,$type,$eventid)
}

#Check if the condition has already been run
If ($env:_EMPNetworkStatus -eq "LANConnect")
{
    write-output "Network connection is ready: Check has already been run"
    writeevent "WaitForNetworkScript" Information 2 "Network connection is
ready: Check has already been run"
    exit 0
}

#Get All physical network adapter which are connected
$connected_physical_nics = Get-WmiObject Win32_NetworkAdapter | `
where {$_.AdapterType -eq "Ethernet 802.3" `
-and $_.PNPDeviceID -match 'PCI' `
-and $_.NetConnectionStatus -eq 2}

#If an adapter is found, we assume client is in corporate network
If ($connected_physical_nics)
{
    #Get the current DC
    $currentDC = ([ADSI]“LDAP://RootDSE”).dnshostname
    #test connection to DC
    $i = 0
    While (!$connrst)
    {
        $connrst = Test-Connection -computername $currentDC -Count 1 -ea
SilentlyContinue
        $i += 1
        If (!$connrst -and $i -ge 15)
        {
            #Timeout, we exit
            write-output "Timeout, we exit the script"
            writeevent "WaitForNetworkScript" Warning 1 "Timeout, network
connection not ready: Error while trying to reach DC: $currentDC"
            exit 1
        }
        start-sleep -s 1
    }
    write-output "Network connection is ready: connected DC: $currentDC"
    writeevent "WaitForNetworkScript" Information 0 "Network connection is
ready: connected DC: $currentDC"
    [ENVIRONMENT]::SetEnvironmentVariable("_EMPNetworkStatus",
"LANConnect", "MACHINE")
    exit 0
}
Else
{
    write-warning "Network is disconnected"
    writeevent "WaitForNetworkScript" Warning 3 "Network is disconnected"
       [ENVIRONMENT]::SetEnvironmentVariable("_EMPNetworkStatus",
"Disconnected", "MACHINE")
    exit 1
}


On 25 April 2013 15:33, James Rankin <[email protected]> wrote:

> That's what I thought....research seems to concur. Delaying the startup of
> certain services might have let me delay the processing long enough for the
> network to connect :-(
>
>
> On 25 April 2013 15:09, Guyer, Don <[email protected]> wrote:
>
>> I thought that setting just delayed GPO processing?****
>>
>> ** **
>>
>> Regards,****
>>
>> * *
>>
>> *Don Guyer**
>> **Catholic Health East - Information Technology*****
>>
>> Enterprise Directory & Messaging Services
>> 3805 West Chester Pike, Suite 100, Newtown Square, Pa  19073****
>>
>> email: *[email protected]*****
>>
>> Office:  610.550.3595 | Cell: 610.955.6528 | Fax: 610.271.9440****
>>
>> *For immediate assistance, please open a Service Desk ticket or call the
>> helpdesk @ 610-492-3839.*
>>
>> [image: Description: Description: Description: InfoService-Logo240]****
>>
>> ** **
>>
>> *From:* James Rankin [mailto:[email protected]]
>> *Sent:* Thursday, April 25, 2013 9:37 AM
>>
>> *To:* NT System Admin Issues
>> *Subject:* Re: Startup processes****
>>
>> ** **
>>
>> Actually hang on, is that right? It delays all the services until the
>> network is available? That might work - but then if *no *network is
>> available, does it start those services at all?****
>>
>> ** **
>>
>> On 25 April 2013 14:22, N Parr <[email protected]> wrote:****
>>
>> GPO  - Always wait for the network at computer startup.
>> Would this setting work for you, it won't let any other services start
>> until the network is available.  Most people turn in on anyway because it
>> solves a lot of other issues.****
>>
>>
>>
>> -----Original Message-----
>> From: [email protected] [mailto:[email protected]]
>> Sent: Thursday, April 25, 2013 7:12 AM
>> To: NT System Admin Issues
>> Subject: Startup processes****
>>
>> On a Windows system, is there a process that runs on startup that will
>> only run if there is network connectivity present? I've got a strange
>> requirement and I need to be able to tell when the network is available, if
>> possible.****
>>
>> TIA,
>>
>>
>> JR
>>
>>
>> Sent from my Blackberry, which may be an antique but delivers email
>> RELIABLY****
>>
>> ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ <
>> http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~
>>
>> ---
>> To manage subscriptions click here:
>> http://lyris.sunbelt-software.com/read/my_forums/
>> or send an email to [email protected]
>> with the body: unsubscribe ntsysadmin
>>
>> ~ Finally, powerful endpoint security that ISN'T a resource hog! ~
>> ~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~
>>
>> ---
>> To manage subscriptions click here:
>> http://lyris.sunbelt-software.com/read/my_forums/
>> or send an email to [email protected]
>> with the body: unsubscribe ntsysadmin****
>>
>>
>>
>>
>> --
>> *James Rankin*
>> Technical Consultant (ACA, CCA, MCTS)
>> http://appsensebigot.blogspot.co.uk****
>>
>> ~ Finally, powerful endpoint security that ISN'T a resource hog! ~
>> ~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~
>>
>> ---
>> To manage subscriptions click here:
>> http://lyris.sunbelt-software.com/read/my_forums/
>> or send an email to [email protected]
>> with the body: unsubscribe ntsysadmin****
>>
>> Confidentiality Notice:
>> This e-mail, including any attachments is the
>> property of Catholic Health East and is intended
>> for the sole use of the intended recipient(s).
>> It may contain information that is privileged and
>> confidential.  Any unauthorized review, use,
>> disclosure, or distribution is prohibited. If you are
>> not the intended recipient, please delete this message, and
>> reply to the sender regarding the error in a separate email.
>>
>>
>> ~ Finally, powerful endpoint security that ISN'T a resource hog! ~
>>
>> ~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~
>>
>> ---
>> To manage subscriptions click here:
>> http://lyris.sunbelt-software.com/read/my_forums/
>> or send an email to [email protected]
>> with the body: unsubscribe ntsysadmin
>>
>>
>
>
> --
> *James Rankin*
> Technical Consultant (ACA, CCA, MCTS)
> http://appsensebigot.blogspot.co.uk
>
> ~ Finally, powerful endpoint security that ISN'T a resource hog! ~
> ~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~
>
> ---
> To manage subscriptions click here:
> http://lyris.sunbelt-software.com/read/my_forums/
> or send an email to [email protected]
> with the body: unsubscribe ntsysadmin
>



-- 
*James Rankin*
Technical Consultant (ACA, CCA, MCTS)
http://appsensebigot.blogspot.co.uk

~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to [email protected]
with the body: unsubscribe ntsysadmin

<<image001.jpg>>

Reply via email to