title: Powershell ForEach loop with embedded IF statements
body: <p>Starting to write powershell scripts (very new) because SCCM tends to respond better to them (both client and server)
  So with the above stated here is my first script:</p>
  
  <pre><code>#Changes the 'ProvisioningMode' Key in the registry to False
  $ProvisiongMode = New-ItemProperty -Path Registry::HKLM\SOFTWARE\Microsoft\CCM\CcmExec -Name ProvisioningMode -Value False -Force
  #Clears or 'nulls' the SystemTaskExcludes key in the registry
  $SystemTaskExludes = New-ItemProperty -Path Registry::HKLM\SOFTRWARE\Microsoft\CCM\CcmExec -Name SystemTaskExcludes - Value "" - Force
  #----------------------------------------------------------------------------------------------
  $Success = "C:\Path\to.log"
  $Failure = "C:\Path\to.log"
  $Computers = Import-Csv "C:\Path\to.csv"
  $SearchStr = Get-ItemProperty -Path Registry::HKLM\SOFTWARE\Microsoft\CCM\CcmExec | select-object ProvisioningMode
  $Online = Test-Conntection -Computername $ComputerName -Count 1 -Quiet
  
  ForEach ($ComputerName in $Computers)
  if ($Online -eq 'False')
  {
      Write-Output $ComputerName`t'Connection Failed'  &gt;&gt; $Failure
  }
  Else
  {
      if ($SearchStr -eq True)
       {
          $ProvisioningMode
          $SystemTaskExcludes 
       }
  
  }
  
  #Second Check
  if ($SearchStr -eq 'False')
  {
      Write-Output $ComputerName`t'Registry has been changed' &gt;&gt; $Success
  }
  </code></pre>
  
  <p>The issue in question is the <code>$Online</code> variable. I would like to see if a computer is responsive to ping, if true then proceed to run <code>$ProvisioningMode</code> and <code>$SystemTaskExclude</code>.
  Then the other issue is querying that key to see if it changed. The issue with that one is <code>$SearchStr = Get-ItemProperty -Path Registry::HKLM\SOFTWARE\Microsoft\CCM\CcmExec | select-object ProvisioningMode</code> returns </p>
  
  <pre><code> ProvisionMode
   -----------------
   False
  </code></pre>
  
  <p>And I cant grab just the <code>false</code> data. 
  Like I stated; very new at powershell and writing something that I will use helps me learn. </p>
  
  <p>Edit: What I Have tried is</p>
  
  <pre><code>ForEach ($Name in $Computers) 
  {
  Test-Connection -BufferSize 2 -Computername $Name.ComputerName -Count 1 -Quiet | Write-Output $Online
  }
  
  if ($Online -eq 'True') {Write-Output $Name`t'Computer is online' &gt;&gt; C:\Online.txt}
  </code></pre>
  
  <p>And many variations of the same thing. </p>
  
  <pre><code> Test-Connection -BufferSize 2 -Computername $Name.ComputerName -Count 1 -Quiet 
  </code></pre>
  
  <p>Returns Data, which is what I want, but I need to input that into an <code>If</code> statement and still retain the <code>$Name</code> for the <code>$StringStr</code> and log files. </p>
  
  <p>Those of you wondering, this takes the client out of provisioning mode when running an OSD. It fixes the 'No Self-Signed Certificate' issue. </p>