VBS Script to PowerShell script

Rohit Bhan 21 Reputation points
2022-02-03T12:23:14.74+00:00

I need your help to convert this VBS script to PowerShell as we are migrating our application to powershell base and need this to be converted ASAP.

Sub DeleteAdminGroup(strSubComputerName)

on error resume next
err.Clear
Set objAdminGroup = GetObject("LDAP://" & strW10AdminOU)
objAdminGroup.Delete "group", "CN=DEL-GCL-" & strSubComputerName & "-Admin"

if Err.number = 0 then
LogFile.WriteLine "SUCCESS: Deleted computer admin group DEL-GCL-" & strSubComputerName & "-Admin from AD"
else
LogFile.WriteLine "ERROR: Cannot delete DEL-GCL-" & strSubComputerName & "-Admin from AD because " & Err.Description
end if
Err.Clear
end sub

Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 47,901 Reputation points
    2022-02-03T16:10:58.297+00:00

    Try this:

    Function DeleteAdminGroup{
        param(
            [string]$strSubComputerName
        )
        $GroupName = "CN=DEL-GCL-{0}-Admin" -f $strSubComputerName
        Try{
            Remove-ADGroup -Identity $GroupName -SearchBase $strW10AdminOU -ErrorAction STOP
            Out-File $Log -InputObject "SUCCESS: Deleted computer admin group $GroupName from AD"
        }
        Catch{
            OutFile $Log "ERROR: Cannot delete $GroupName $_"
        }
    }
    

    I don't know where the log file name is declared, or where the strW10AdminOU is declared. I'm assuming they somewhere in the script outside the function.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.