Export results to CSV
-
23. dubna 2012 17:51can anyone help me export results to CSV
$searchRoot = 'cd.ds.bsu.edu/Academic Affairs/AG/Computers'
$age = 120 # in days
$accounts = Get-QADComputer -IncludedProperties LastLogonTimeStamp -SearchRoot $searchRoot | Sort-Object -Property LastLogonTimeStamp -Descending
$today = Get-Date
foreach( $account in $accounts )
{
if( $account.LastLogonTimeStamp -eq $null )
{
Write-Host $account.Name "last logon: Never"
}
else
{
$res = $today - $account.LastLogonTimeStamp
$days = $res.Days
if( $days -gt $age )
{
Write-Host $account.Name "last logon:" $days "days ago"
}
}
}bradley Wyatt
Všechny reakce
-
23. dubna 2012 17:59Unless you pressed a wrong button, you are messing this forum around. You have already asked this question. Why are you posting it again?
Grant Ward, a.k.a. Bigteddy
What's new in Powershell 3.0 (Technet Wiki)
- Upravený BigteddyMicrosoft Community Contributor 23. dubna 2012 17:59
-
23. dubna 2012 18:01
The last question I had posted resulted it an entirely different script tat would not export. I was seeing if anyone else had any ideas on how to do it. I wanted it to be something like the following:
| Select-Object Name, SAMAccountName, LastLogon|Export-CSV C:\csv\file.csvJust a csv with what it throws me on PowerShell
bradley Wyatt
I took your new advice on the previous post and it compiled a blank csv as well. Just looking for other input as well- Upravený Bradley Wyatt 23. dubna 2012 18:03
-
23. dubna 2012 18:19
This works. If you wrote that script, you will know how to fit the code into this structure:
$numbers = 0..9 $results = @() foreach ($number in $numbers) { $tobj = New-Object psobject $tobj | Add-Member -MemberType noteproperty -Name 'Number' -Value $number if ($number % 2 -eq 0) {$tobj | Add-Member -MemberType noteproperty -Name 'Type' -Value 'Even'} else {$tobj | Add-Member -MemberType noteproperty -Name 'Type' -Value 'Odd' } $results += $tobj } $results | Export-Csv me.csv -Force Import-Csv me.csv | Format-Table -AutoSizeGrant Ward, a.k.a. Bigteddy
-
23. dubna 2012 18:49I wrote the script but never implemented $results, $tobj within the script. That is why I am having troubles.
bradley Wyatt
-
23. dubna 2012 19:28I found out how to do it the right way. Thanks for the help anyways
bradley Wyatt
-
24. dubna 2012 2:39Moderátor
-
3. května 2012 21:30$results | Export-Csv me.csv -Force
bradley Wyatt