Posts

Showing posts from May, 2016

PowerShell - Retrieve AD Computers Properties

# Retrieve AD computer properties such as LastLogonDate. # The list of machine need to be added in hosts.txt file in script folder # The result will be saved to Output.csv file in script folder Import-Module ActiveDirectory $invocation = (Get-Variable MyInvocation).Value $directorypath = Split-Path $invocation.MyCommand.Path $input = $directorypath + "\host.txt" $output = $directorypath + "\output.csv" Get-Content $input | ForEach-Object { Get-ADComputer $_ -Properties * | Select-Object Name,LastLogonDate,OperatingSystem,OperatingSystemServicePack,OperatingSystemVersion,WhenCreated,Description }   | Export-Csv $output

PowerShell - Copy AD Group membership

#Copy group membership from source group to target group Import-Module ActiveDirectory $gsource =Get-ADGroup "Test Group1" $gtarget = Get-ADGroup "Test Group2" Get-ADGroupMember -Identity $gsource | foreach { Add-ADGroupMember -Identity $gtarget -Members $($_.DistinguishedName) }