need cmdlet or ps script

Welcome Forums General PowerShell Q&A need cmdlet or ps script

This topic contains 1 reply, has 2 voices, and was last updated by

3 years, 5 months ago.

  • Author
  • #35022

    Topics: 16
    Replies: 9
    Points: 0
    Rank: Member

    $hddts=Get-ADComputer -Filter 'name -like "hddt*"'|select -ExpandProperty name
    foreach($hddt in $hddts){if(Test-Connection -ComputerName $hddt -Count 1 -Quiet){
    $hddt|Out-File C:\Users\dt203976\Desktop\hddtpingable.txt}
    else{$hddt|Out-File C:\Users\dt203976\Desktop\hddtnotpingable.txt}

    above is my script to test the connection to AD computers , my requirement is to copy all the live machines to one txt file and not in live machines to another txt file .

    but here, file name "hddtpingable.txt" is replacing existing data with current instead writing sequence , please help in correcting myscript by adding any cmdlet which fulfil my requirement

  • #35023

    Topics: 13
    Replies: 4872
    Points: 1,842
    Helping HandTeam Member
    Rank: Community Hero

    Look at the help for Out-File and see if the -Append parameter has any use to your requirement.

The topic ‘need cmdlet or ps script’ is closed to new replies.