2015-11-19

Quick glance at PowerShell environment

Logging in to a new system and need to know what my PowerShell capabilities are.

To have a quick overview of what I can do on that box I do this:


Write-Host "Installed PowerShell version: $($PSVersionTable.PSVersion.Major).$($PSVersionTable.PSVersion.Minor)"
Write-Host "Available PowerShell modules:"
Get-Module -ListAvailable | Select Name



2015-11-16

Rename Active Directory groups with PowerShell

I was struggling with this one because there are several different name attributes for AD objects, name, DisplayName, SamAccountName, cn, etc.

I finally ended up with this solution which seems to rename all name attributes:


Import-Module ActiveDirectory

$TargetGroups = Get-ADGroup -Filter {Name -like "XXXDescription*"}

ForEach($SingleGroup in $TargetGroups)
{
    Write-Host "Old name: $($SingleGroup.Name)"
    $NewGroupName = $($SingleGroup.Name).Replace('XXXDescription','YYYYZZZZDescription')
    Write-Host "New name: $($NewGroupName)"
    Get-ADGroup $SingleGroup | Set-ADGroup -DisplayName $NewGroupName -SamAccountName $NewGroupName
    Get-ADGroup $SingleGroup | Rename-ADObject -NewName $NewGroupName
}
If there is a nicer solution, please feel free to post it in the comments.