Solved

What are the code changes required to run power shell script in command prompt

  • 27 September 2022
  • 1 reply
  • 33 views

Badge

[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
$systemProxy = [System.Net.WebRequest]::GetSystemWebproxy()
$systemProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
$proxy = $systemProxy.GetProxy("https://cym-rt-resources.s3-eu-west-1.amazonaws.com/Import-ActiveDirectory.ps1")
if ($proxy.AbsoluteUri -ne "https://cym-rt-resources.s3-eu-west-1.amazonaws.com/Import-ActiveDirectory.ps1"){
    iex (new-Object Net.WebClient).DownloadString('https://cym-rt-resources.s3-eu-west-1.amazonaws.com/Import-ActiveDirectory.ps1')
}else {
    iex (new-Object Net.WebClient).DownloadString('https://cym-rt-resources.s3-eu-west-1.amazonaws.com/Import-ActiveDirectory.ps1')
}
Import-ActiveDirectory

$dcfqdn = 'default.local'
if($dcfqdn -eq "default.local"){
  $domain = Get-ADDomainController | Select Domain
  $dc = Get-ADDomainController | Select Name
  $dcfqdn = $dc.Name+"."+$domain.Domain
}

$string_path = Split-Path $env:temp\adfind.exe

$env:temp\adfind.exe -h $dcfqdn -s Sub -root -f '(Name=Domain Admins)' member -list | $env:temp\adfind.exe -h $dcfqdn -f objectcategory=*
 

icon

Best answer by ruib 28 September 2022, 09:38

View original

1 reply

Replace the last line with:

& "$env:temp\adfind.exe" -h $dcfqdn -s Sub -root -f '(Name=Domain Admins)' member -list | & "$env:temp\adfind.exe" -h $dcfqdn -f objectcategory=*

 

The execution will also work if you download adfind.exe to a different explicit path, e.g. c:\temp.

Reply