asked on
# Define local groups to audit
$groups = "Administrators", "Remote Desktop Users";
# Add Active Directory powershell plug-in
import-module activedirectory;
# Get all servers from AD and ignore predefined list
$adservers = get-adcomputer -filter {operatingsystem -like "*server*"} | where {$_.enabled -eq $true} | sort name;
# Loop through each server found in AD
foreach ($adserver in $adservers) {
# Set server name from AD object
$servername = $adserver.name;
# Check if server is pingable
if((test-connection -computername $servername -count 1 -quiet)) {
# Loop through each group to audit
foreach ($group in $groups) {
# Define the localgroup in the correct format
$localgroup = [ADSI]"WinNT://$servername/$group";
# Get members of the local group
$members = @($localgroup.Invoke("Members"));
# Loop through each member found
foreach ($member in $members) {
# Define name and type of the member
$memberName = $member.GetType().Invokemember("Name","GetProperty",$null,$member,$null);
$memberType = $member.GetType().Invokemember("Class","GetProperty",$null,$member,$null);
# Build CSV string
$outstring = $servername + "," + $group + "," +$membername + "," +$membertype;
# Output string to screen
write-host $outstring;
# Append CSV string to file
$outstring >> c:\temp\localgroupaudit.csv;
}
}
}
}
A scripting language is a programming language that supports scripts, programs written for a special run-time environment that automate the execution of tasks that could alternatively be executed one-by-one by a human operator. Scripting languages are often interpreted (rather than compiled). Primitives are usually the elementary tasks or API calls, and the language allows them to be combined into more complex programs. Environments that can be automated through scripting include software applications, web pages within a web browser, the shells of operating systems (OS), embedded systems, as well as numerous games. A scripting language can be viewed as a domain-specific language for a particular environment; in the case of scripting an application, this is also known as an extension language.
TRUSTED BY
Open in new window