0

I am calling Get-AdComputer like this:

[string[]] $computer = Get-ADComputer -properties * -filter {(operatingsystem -like "*Windows 7*")} |
    Where-Object {$_.name -like "*-*"} |
    Where-Object {$_.name -NotLike "V7-*"} |
    Where-Object {$_.name -NotLike "*-NONE"} |
    Where-Object {$_.name -NotLike "*-ONCALL"} |
    Where-Object {$_.name -NotLike "*-BLACKBAUD"} |
    Where-Object {$_.name -NotLike "SC-WIN7-1"} |
    Where-Object {$_.name -NotLike "UT-SWCLIENT-01"} |
    Select-Object Name, LastLogonDate

This creates a string array and I can access it like this:

$computer[1]

which returns

@{Name=W7-9HQPR3J; LastLogonDate=05/08/2017 09:45:13}

I need to output the data to a csv file in two columns Name, LastLogonDate

Unfortunately when I call $Computer | out-file -filepath $ServiceTagsPath -Force -Width 200 -Encoding ascii

I get one column with the headings on each line: enter image description here

My other requirement is to be able to use the Name column in web-service calls to get warranty information...

so how could I do that?

1
  • Sign up for the Dell TechDirect API, there's one for Warranty, using these will be much easier than scraping the values from an HTML page. You can request the info you want in a format that powershell can deal with natively: techdirect.dell.com/portal.30/AboutAPIs.aspx Commented Apr 17, 2018 at 13:55

1 Answer 1

4

I would not cast the output to array of strings [string[]] but leave the casting to powershell. Then you can use command Export-Csv which works better with array of objects.

$computer = Get-ADComputer -properties * -filter {(operatingsystem -like "*Windows 7*")} |
    Where-Object {$_.name -like "*-*"} |
    Where-Object {$_.name -NotLike "V7-*"} |
    Where-Object {$_.name -NotLike "*-NONE"} |
    Where-Object {$_.name -NotLike "*-ONCALL"} |
    Where-Object {$_.name -NotLike "*-BLACKBAUD"} |
    Where-Object {$_.name -NotLike "SC-WIN7-1"} |
    Where-Object {$_.name -NotLike "UT-SWCLIENT-01"} |
    Select-Object Name, LastLogonDate

 $computer | Export-Csv "test.csv" -NoTypeInformation
Sign up to request clarification or add additional context in comments.

4 Comments

this outputs a csv with #TYPE System.String as the heading and all records are just the number 53
I think you have copied the code from @Shawn Esterman or try to flush the variable by Remove-Variable or simply close and open shell window again
@OurManinBananas note that [string[]] has been removed in this answer.
@pandemic: no, I took that out... and set the $computer variable to $null

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.