Forum Discussion

Bittu_8148's avatar
Bittu_8148
Copper Contributor
Feb 01, 2022
Solved

Unable to save the Output to file location

Hi, Please find below code. I am unable to save the Output to file location. I have created the $Filepath to create new folder with year, if it is created it will ignore automatically since I have...
  • Harm_Veenstra's avatar
    Feb 01, 2022

    Bittu_8148 

     

    You're putting the command to create the folder in a variable, that's one reason. Other reason is the formatting of the file, I changed it a little bit 🙂

     

    New-Item -ItemType Directory -Force -Path "C:\ADComputers\$((Get-Date).tostring("yyyy"))"
    $Filepath = "C:\ADComputers\$((Get-Date).tostring("yyyy"))"
    $filename=(Get-Date).tostring("dd-MM-yyyy-hh-mm-ss")
    Get-ADComputer -Filter * -Property * | Select-Object Name,enabled,OperatingSystem,OperatingSystemVersion,ipv4Address,lastlogondate,CanonicalName |
    Export-CSV -Path ($Filepath + '\'+ "ÁDComputers_Report_$($filename).csv") -Force -Delimiter ','-NoTypeInformation -Encoding UTF8
    

Resources