[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 74
  • Last Modified:

Doh - Powershell works in ISE not as a scheduled task.

I have a powershell script I put together that collects AD information from three separate domains and assembles the information into a worksheet with graphs and calculations and all that fun stuff.

Works great in ISE.

But when I go to schedule it as a task, it hangs up on connecting to the AD domain controllers.

Here is the line where it seems to get stuck:
$subOUs = Get-ADOrganizationalUnit -Filter * -SearchBase $thisDN -properties cn,description -SearchScope OneLevel -Server $domainDC -Credential $credential

Open in new window


$domainDC is the domain controller I'm connecting to and $credential is a PS credential assembled from password files.

$uname = $domain.domain + "\Administrator"
    $pFile = $credentialFolder + $domain.domain + "_password.pwd"
    $password = Get-Content $pFile | ConvertTo-SecureString
    $credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $uname,$password

Open in new window


Any idea why I'm getting suck here?
0
Dustin Saunders
Asked:
Dustin Saunders
1 Solution
 
Adam BrownSr Solutions ArchitectCommented:
Is your script adding the AD module when it runs through the scheduled task? Scheduled tasks run the default Powershell without modules, so that will need to be there if it isn't.
0
 
QlemoC++ DeveloperCommented:
The password file is encrypted, making it valid only for the machine and user account you created it on/in. The scheduled task has to run with the same user the ISE has been tested with.
1
 
Dustin SaundersDirector of OperationsAuthor Commented:
Ah!  Yeah, that's the problem, good to know.  Thanks Qlemo!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now