<# Created By Abhishek Bansal
Read Note
Script Usage - Fetching all Windows Server details in the domain from Active Directory. Useful in doing inventory management.
Pre requisites :: Copy all the code into a text file, save it with an extension ".PS1". Once saved, run this script as Administrator
Execution & Outputs :: Once executed, there will be two Output files created as -
ADCompdetails.csv - Containing details of all the Windows server found in Active Directory.
Errorlogs.csv - Logs any error while fetching the uptime.#>
$inputsrv = $(Get-ADComputer -Filter * -Properties OperatingSystem | ?{$_.OperatingSystem -match "Server"}).Name
foreach($server in $inputsrv)
{
$error.Clear()
try{
Get-ADComputer -Identity $server -Properties * | Select Name,OperatingSystem,DistinguishedName,IPv4Address,Enabled,Created | Export-Csv ./ADCompdetails.csv -NoTypeInformation -Append
}
catch
{
$server | Select-Object -Property @{n="Hostname";e={$server}},@{n="ErrorMessage";e={$error.exception.Message}} | Export-Csv ./Errorlogs.csv -NoTypeInformation -Append
}
}
No comments:
Post a Comment