Pages

Monday, 15 August 2022

looping

$count = 0

$success = $null

# 1. This is to make sure the script is running. We can add this in network log file since the machine is not connected to network.

 $logfile_Temp = "C:\temp\CheckRunning.log"

 Add-Content $logfile_Temp -Value "This is to check the Gpupdate_DSRRedCmd.Ps1 is runnung or not"

 Do{
  try{

  # 1. Checking the VPN is connected to CISCO Anyconnect Mobility client.

 $NIC = Get-NetIPConfiguration | ? {$_.NetAdapter.status -eq "UP"} | Select-Object InterfaceDescription

if ($NIC -match "Cisco AnyConnect Secure Mobility Client Virtual Miniport Adapter for Windows")

 {

  Start-Sleep -Seconds 60

 $location = "\\housccm309\incoming$\Windows 10 Enterprise"

$comname = $env:computername

$logfile = "$location\$comname.log"

  Add-Content $logfile -Value "Machine is connected to Cisco AnyConnect Secure Mobility client "

 $success = $true

  Add-Content $logfile -Value "Executing Gpupdate /force wating time is 3 minutes"

  gpupdate /force

  Start-Sleep -Seconds 180

 Add-Content $logfile -Value "Gpupdate is executed successfully"

$oseditionwin10 = (Get-WmiObject -class Win32_OperatingSystem).Caption

Add-Content $logfile -Value "Machine is changed to $oseditionwin10"

 }

 ElseIF ($NIC -like "*Pulse*")

 {

 Start-Sleep -Seconds 60

 $location = "\\housccm309\incoming$\Windows 10 Enterprise"

$comname = $env:computername

$logfile = "$location\$comname.log"

Add-Content $logfile -Value "Machine is Connect to Pulse VPN"

  $success = $true

  Add-Content $logfile -Value "Executing Upupdate /force wating time is 3 minutes"

  gpupdate /force

  Start-Sleep -Seconds 180

 Add-Content $logfile -Value "Gpupdate is executed successfully"

 $oseditionwin10 = (Get-WmiObject -class Win32_OperatingSystem).Caption

Add-Content $logfile -Value "Machine is changed to $oseditionwin10"

    }

 Else

 {Add-Content $logfile_Temp -Value "Machine is waiting to join network"

}

 }

  catch {

    $location = "\\housccm309\incoming$\Windows 10 Enterprise"

$comname = $env:computername

$logfile = "$location\$comname.log"

Add-Content $logfile -Value "Error"

    }

  $count++

 }until($success)

No comments:

Post a Comment

User based detection

function getloggedindetails () {     ##Find logged in username     $user = Get-WmiObject Win32_Process - Filter "Name='explorer...

Search This Blog