diff --git a/Active Directory/Rename-GPOsByCSV.ps1 b/Active Directory/Rename-GPOsByCSV.ps1 index 769724a..c5abe1f 100644 --- a/Active Directory/Rename-GPOsByCSV.ps1 +++ b/Active Directory/Rename-GPOsByCSV.ps1 @@ -64,6 +64,9 @@ function Rename-GPOsByCSV { Write-Log "$StartTime `n" Import-Module GroupPolicy + + [string]$Domain = [System.DirectoryServices.ActiveDirectory.Domain]::GetComputerDomain().Name + } # end begin block process { @@ -90,14 +93,14 @@ function Rename-GPOsByCSV { foreach ($gpo in $Batch) { try { # Get the old GPO and rename it: - $OldGpo = (Get-GPO -Name $gpo.OldName -ErrorAction Stop).DisplayName + $OldGpo = (Get-GPO -Name $gpo.OldName -Domain $Domain -ErrorAction Stop).DisplayName # Check if -WhatIf parameter is specified $Target = "$($gpo.OldName)" $Operation = "Rename to '$($gpo.NewName)'" if ($PSCmdlet.ShouldProcess($Target, $Operation)) { # Rename the GPO and suppress the host output - Rename-GPO -Name $OldGpo -TargetName $gpo.NewName | Out-Null + Rename-GPO -Name $OldGpo -TargetName $gpo.NewName -Domain $Domain | Out-Null Write-Log -LogText "$(Get-Date) [Success] Renamed GPO '$Target' to '$($gpo.NewName)'." -Output Both } else { Write-Log -LogText "$(Get-Date) [Skipped] $Target" -Output Both diff --git a/Active Directory/Rename-GroupsByCsv.ps1 b/Active Directory/Rename-GroupsByCsv.ps1 index 7d89d4d..323a776 100644 --- a/Active Directory/Rename-GroupsByCsv.ps1 +++ b/Active Directory/Rename-GroupsByCsv.ps1 @@ -59,6 +59,9 @@ function Rename-GroupsByCsv { } Import-Module ActiveDirectory + + [string]$Domain = [System.DirectoryServices.ActiveDirectory.Domain]::GetComputerDomain().Name + } # end begin block process { @@ -66,7 +69,7 @@ function Rename-GroupsByCsv { try { $OldName = $group.GroupName $NewName = $group.NewGroupName - Get-ADGroup $OldName | Set-ADGroup -SamAccountName $NewName -DisplayName $NewName -WhatIf + Get-ADGroup $OldName -Server $Domain | Set-ADGroup -SamAccountName $NewName -DisplayName $NewName -Server $Domain -WhatIf Write-Log -LogText "$(Get-Date) [Renamed] `'$OldName`' renamed to `'$NewName`'." -Output Both } catch { Write-Log -LogText "$(Get-Date) [Failed] Failed to rename `'$OldName`'.`n$_" -Output Both