In PowerShell, complexity is hidden in the background.
Administrator or PowerShell users can do more with less coding.
Code example below will set computer description in Active Directory via a text file.
Text file name is “computers.txt” in D drive location. (Of course this file can be located anywhere and any file name as well.)
Anyway for the sake of this example, the file name is “computers.txt” and file is located on root of D drive.
Text file structure should be something like this:
Comp1A-User1A
Comp1B-User1B
In which, Comp1A is the computer name and User1A is the computer description. "-" is jut a delimiter for the two unique value.
PowerShell Script below uses Get-ADComputer cmdlet to get the reference of the Computer object and Set-ADComputer to set the data to computer object property.
Since the Text file is separated by "-". Computer Name-Computer Description
This line below will split the data into array.
$TxtFileVar = $_ -split '-'
Write-Host $TxtFileVar[0]; Write-Host $TxtFileVar[1]
This command below will set the computer description in Active Directory.
$comp = Get-ADComputer $TxtFileVar[0]; $comp.Description = $TxtFileVar[1]; Set-ADComputer -Instance $comp
Below is the full script:
===============================
$TxtFileVar = Get-Content "d:\computers.txt"
$TxtFileVar | foreach {
$TxtFileVar = $_ -split '-'
Write-Host $TxtFileVar[0]; Write-Host $TxtFileVar[1]
$comp = Get-ADComputer $TxtFileVar[0]; $comp.Description = $TxtFileVar[1]; Set-ADComputer -Instance $comp
}
================================
Sample Output of Write-Host command:
User1A
Comp1A
User1B
Cheers!! Enjoy.. Hope it helps.
=================================
Check out this free Android app.
Free Catholic Prayer Android App, No Ads.
Pray everyday, keep the faith and live with Hope.
https://play.google.com/store/apps/details?id=soulrefresh.beautiful.prayer
Android Rosary Guide (Free)
https://play.google.com/store/apps/details?id=com.myrosaryapp
Free Catholic Prayer Android App, No Ads.
Pray everyday, keep the faith and live with Hope.
https://play.google.com/store/apps/details?id=soulrefresh.beautiful.prayer
Android Rosary Guide (Free)
https://play.google.com/store/apps/details?id=com.myrosaryapp
Comments
Post a Comment