Question : Change the powershell script to write to a file rather than updating to the computer object.

Hi,

Change the powershell script to write to a file rather than updating to the computer object.
Can anyone help with the change to do this.

Computername : (Contacts: 0 days) (Online: 138.22 hours)

Regards
Sharath
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
$DomainControllers = "in1"

$Computers = @{}
$DomainControllers | ForEach-Object {
  Get-QADComputer -SearchRoot "Developmuk/Countries/ID/Chi/Virines" -Service $_ -SizeLimit 0 -IncludedProperties LastLogon | `
    Select-Object Name, DN, LastLogon | ForEach-Object { 
      If ($Computers.$($_.DN)) {
        $Computers.$($_.DN) = $_ | Select-Object Name, DN, `
          @{n='LastLogon';e={ 
            If ($_.LastLogon -gt $Computers.$($_.DN).LastLogon) { 
              $_.LastLogon 
            } Else { 
              $Computers.$($_.DN).LastLogon 
            } }}
      } Else {
        $Computers.Add($_.DN, $_)
      }
    }
}

$Computers.Values | ForEach-Object {
  $LastLogon = (New-TimeSpan $_.LastLogon).Days

  If (Test-Connection $_.Name -Quiet -Count 1) {
    $LastBootUpTime = (Get-WmiObject Win32_OperatingSystem -Computer $_.Name).LastBootUpTime
    If ($LastBootUpTime -ne $Null) {
      $LastBootUpTime = [Management.ManagementDateTimeConverter]::ToDateTime($LastBootUpTime)

      $Online = [Math]::Round((New-TimeSpan $LastBootUpTime).TotalHours, 2)
    }
  } Else {
    $Online = 0
  }

  Set-QADComputer $_.DN -Description "(Contacts: $LastLogon days) (Online: $Online hours)"
}

Answer : Change the powershell script to write to a file rather than updating to the computer object.


Ah sorry, missing a closing ".

Chris
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
$DomainControllers = "in1"

$Computers = @{}
$DomainControllers | ForEach-Object {
  Get-QADComputer -SearchRoot "Developmuk/Countries/ID/Chi/Virines" -Service $_ -SizeLimit 0 -IncludedProperties LastLogon | `
    Select-Object Name, DN, LastLogon | ForEach-Object { 
      If ($Computers.$($_.DN)) {
        $Computers.$($_.DN) = $_ | Select-Object Name, DN, `
          @{n='LastLogon';e={ 
            If ($_.LastLogon -gt $Computers.$($_.DN).LastLogon) { 
              $_.LastLogon 
            } Else { 
              $Computers.$($_.DN).LastLogon 
            } }}
      } Else {
        $Computers.Add($_.DN, $_)
      }
    }
}

$Computers.Values | ForEach-Object {
  $LastLogon = (New-TimeSpan $_.LastLogon).Days

  If (Test-Connection $_.Name -Quiet -Count 1) {
    $LastBootUpTime = (Get-WmiObject Win32_OperatingSystem -Computer $_.Name).LastBootUpTime
    If ($LastBootUpTime -ne $Null) {
      $LastBootUpTime = [Management.ManagementDateTimeConverter]::ToDateTime($LastBootUpTime)

      $Online = [Math]::Round((New-TimeSpan $LastBootUpTime).TotalHours, 2)
    }
  } Else {
    $Online = 0
  }

  $_ | Select-Object Name, @{n='LastLogon';e={ $LastLogon }},  @{n='Online';e={ $Online }}
} | Export-Csv "report.csv"
Random Solutions  
 
programming4us programming4us