Thursday, December 18, 2014

Get local admins remotely using PowerShell

Small script that I've created to retrieve local admins users remotely from a list of computers.

######################

$List = "127.0.0.1", "localhost"

### This can be change to $List = Get-Content C:\ComputerList.txt
### In order to include a large list of computers to go through them

######################

$Results = foreach ($l in $list)
{
    
    $Result = "" | Select-Object -Property ComputerName, LocalAdmin
    $Result.ComputerName = $l
    $AllUsers = Get-WmiObject -Class win32_groupuser -ComputerName $l -ErrorAction 'SilentlyContinue'
    $Local_Administrators = $AllUsers | Where { $_.GroupComponent -match 'administrators' }
    $Result.LocalAdmin = ""
    $Result.LocalAdmin = $Local_Administrators | ForEach-Object {`
        $PartComponent = $_.PartComponent;
        $output = $PartComponent.LastIndexOf('=');
        $output = $PartComponent.Substring($output);
        $output = $output.Substring(2);
        $output.TrimEnd('"')
    }
    $LocaAdminsCount = $Result.LocalAdmin.Count
    $ConvertToCSV = ""
    for ($i = 0; $i -le $LocaAdminsCount; $i++)
    {
        if ($i -lt ($LocaAdminsCount - 1))
        {
            $ConvertToCSV += $Result.LocalAdmin[$i] + ", "
        }
        else
        {
            $ConvertToCSV += $Result.LocalAdmin[$i]
        } # END IF
    } # END for loop
    $Result.LocalAdmin = $ConvertToCSV
    $Result
    
} # END foreach loop

$Results # Just display the result to the screen
$Results | Export-Csv $env:TEMP\LocalAdmin.csv

### Change the output location to whatever you would like

######################

Enjoy :-)

Thursday, November 27, 2014

Configuring Task Scheduler with GPO

About

First, This is not a guide of how to create a GPO that will deploy a Task,
If you are looking for a "How To" guide you can search Google or just follow the below link:
http://technet.microsoft.com/en-us/library/dd851678.aspx

Problem

I noticed a weird problem while configuring a Task using GPO,
The Task configure by default to be disabled and there isn't any conventional way to enable it,
See for example:

GPO Setting:

The ability to enable the task is not exists, once the policy been refreshed you will noticed that the affected machine/server will show the task as Disabled.

I found this issue on Server 2012, haven't tested it on Server 2008R2 or below.

Solution 

In the Group Policy editor extract the UID of the GPO, mine was -
{476EA74A-DA3A-4497-AE39-310031C6813F}

Then, I navigate to the SYSVOL folder, which holds every GPO,
and {476EA74A-DA3A-4497-AE39-310031C6813F} folder i edited the XML file associated to the GPO.

See below:

I change the value of the Enabled XML tag from false to true, and saved the XML file.

That's it!

Once done that the Task showed as Enable and on the end Machine/Server after a policy refresh it appeared as Activated.

Hope this helps. 




Tuesday, November 18, 2014

Display Room Temperature Using LM35 Temp Sensor

Required

  • 1 x Arduino Board
  • 1 x 7 Segment 4 Digit Display (in my case common anode)
  • 1 x LM35 Temperature Sensor
  • 1 x Bread Board
  • 8 x 330 Ohm resistors
  • 15 x Wires (for the connections)

The Basics


Most of the guides i came across with on the Internet instructed how to connect and retrieve the temperature from the LM35 sensor and display them using the Arduino serial monitor.
I want to do something a bit different, i'm sure there is already a guide on the Internet about it, but i wanted to do something of my own.

In this guide you will learn how to connect both 7 segment 4 digit display and LM35, and, finally display the room temperature on the display.

Connecting the 7 Segment 4 Digit Display:

You may refer to my previous blog on 7 Segment 4 Digit Display at located here
 

Connecting the LM35 Temperature Sensor:


+Vs    --> 5V pin on Arudino
Vout   --> Analog 0 pin on Arduino
GND  --> GND pin on Arduino










Example -


















Finally you should have something like this (Including the 7 Segment):

An overview look of how i have connected my device.











A closer look at the LM35 temp sensor.













 

The Code

#include <SevenSeg.h>

// Seven Seg Global Variables
SevenSeg disp(2, 3, 4, 5, 6, 7, 8);
const int numOfDigits = 4;
int digitPins [numOfDigits] = {10, 11, 12, 13};

// LM35 Temp Sensor Global Variables
// Based on http://playground.arduino.cc/Main/LM35HigherResolution
int LM35Pin = 0; //Analog pin connected to LM35
//float referenceVoltage;
float SensorValue = 0; // a variable that will hold the temp sensor input

void setup() {

  // Serial Interface Setup
  Serial.begin(9600);

  // Seven Seg Setup: 
  // define number of digits and the location on Arduino pins
  disp.setDigitPins(numOfDigits, digitPins);
  // define decimal point Arduino pin
  disp.setDPPin(9);
  // set refresh rate, how many times the display will refresh in seconds, more is faster.
  disp.setRefreshRate(60);

  // LM35 Temp Sensor Setup
  analogReference(INTERNAL); // This will limit the current to 1.1V for higher resultion
  //referenceVoltage = 1.1; //Set to 5, 3.3, 2.56 or 1.1 depending on analogReference Setting
  // The LM35 with this configuration is limit to 0 - 110 Celisus
  // For more information see: http://arduino.cc/en/Reference/AnalogReference//END setup()

void loop(){

  SensorValue = float(analogRead(LM35Pin)) * 110 / 1024;
  SensorValue = SensorValue * 100;
  Serial.print("TempC = ");
  Serial.print(SensorValue);
  Serial.println();

  for(int i = 0; i <= 100; i++) {
    disp.write(SensorValue, 2);
  }

} // END loop()

Friday, November 14, 2014

Common Anode 7 Segment 4 Digit Display

Device:

 

Common anode 5461BS

Datasheet:





About:

I have search the web for a simple tutorial of how to connect and use a 7 Segment 4 Digit display,
I had a small idea to create a digital temperature monitor with the LM35 temperature sensor, but before that i had to understand how to work with the 7 segment 4 digit display.

I have connected the 5461BS device to the Arduino board as describe below -
























my device is a common anode device, and since, i had to connect a resistor between each LED to the Arduino digital pin in order to lower the voltage and not to damage the LED light, i choose a 330ohm resistor, because this is what i had at the moment. An higher resistor number, means a dimmed LED.


The Code:

I found a very good and sufficient library from the following link -
http://playground.arduino.cc/Main/SevenSeg

All i had to do is to read the "How To" manual and very quickly understand how to control the 7 segment 4 digit device.

the below example code will count from 0 to 2014 and will stay on 2014 on the 7 Seg device -

// Include 7 Segment 4 Digit library
#include <SevenSeg.h>

// Define the connection between the segment to the arduino,
// Example - Arduino Pin 2 equiles LED a on the display
SevenSeg disp(2, 3, 4, 5, 6, 7, 8);
// Set number of digit to display
const int numOfDigits = 4;
// Define which Arduino Digital Pins will control the Digits
int digitPins [numOfDigits] = {
  10, 11, 12, 13};
// Declare x variable to the IF statment below
int x = 0;

void setup() {

  // Define SevenSeg to use 4 digits and where they are located
  disp.setDigitPins(numOfDigits, digitPins);
  Serial.begin(9600);
  disp.setDPPin(9); // Setup the Decimal Point
  disp.setRefreshRate(50); // Lower number means flickring LED

}
void loop(){

  // A very basic code that will count to 2014 and then stop 
  if (x == 0) {
    for(x = 0; x <= 2014; x++){
      disp.write(x);
      Serial.println(x);
    }
  } 
  else {
    disp.write(2014);
  }

}