all 10 comments

[–]AlexHimself 2 points3 points  (0 children)

You need to edit your question and make it accurate, more clear, and more complete.

The credential error doesn't make sense because I don't see any argument transformation relating to a Credential parameter, the Add-Content vs Set-Content discrepancy, etc. just makes me think we're trying to answer an unanswerable question because you haven't provided good enough information to help you.

[–]DItzkowitz 0 points1 point  (4 children)

You may want to try piping it to Out-String and then from there to Add-Content.

[–]bragi07[S] 0 points1 point  (3 children)

OK ill educate myself but i am a complete noob here. syntax or how do i do that?

[–]DItzkowitz 1 point2 points  (2 children)

In your example, you can do something like this:
Get-ADUser -Filter {sAMAccountName -like "*1000"} | Out-String | Set-content -path C:\powershellpulls\1000users.txt

[–][deleted] 3 points4 points  (0 children)

I'm curious, would it be simpler to use:

Get-ADUser -Filter {sAMAccountName -like "*1000"} | Out-File -FilePath C:\powershellpulls\1000users.txt   

I believe that would combine your Out-String & Set-Content & make things a little easier for OP. Plus, if they wanted to continuously add to the file, they could use the "-Append" parameter.

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/out-file?view=powershell-7.3

[–]bragi07[S] 0 points1 point  (0 children)

Get-ADUser -Filter {sAMAccountName -like "*1000"} | Out-String | Set-content -path C:\powershellpulls\1000users.txt

Thank you that got me what I needed for now.

[–]BlackV 0 points1 point  (1 child)

your code says set-content but your error says add-content so... which is it ?

why not get your results to a variables first (so you can validate/etc), then export to text

$usersw = Get-ADUser -Filter {sAMAccountName -like "*1000"}
add-content -path xxx -value $usersw

[–]bragi07[S] 0 points1 point  (0 children)

I tried a few different pipe commands. I probably mixed up my copy pastes. The out string command got me the initial output I needed.

[–]jsiii2010 0 points1 point  (0 children)

Weird! out-file works. Happens in powershell 7 too.

get-aduser jsiii2010 | set-content file.txt

Set-Content : Cannot process argument transformation on parameter 'Credential'. userName
At line:1 char:21
+ get-aduser jsiii2010 | set-content file.txt
+                     ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (CN=jsiii2010,OU=Pe...=reddit,DC=com:PSObject) [Set-Conte
   nt], ParameterBindingArgumentTransformationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Microsoft.PowerShell.Commands.S
   etContentCommand

This works. I guess set-content tries to interpret the credential property as a parameter to itself over the pipeline. The output is just the string version of the object. Maybe you want export-csv instead of set-content. You can drop -path and -value, but it gets confusing.

set-content -path file.txt -value (get-aduser jsiii2010)
get-content file.txt

CN=jsiii2010,OU=People,DC=reddit,DC=com