Solved

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

Posted on 2016-07-25
3
48 Views
Last Modified: 2016-07-25
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
Comment
Question by:Dustin Saunders
3 Comments
 
LVL 39

Expert Comment

by:Adam Brown
ID: 41728490
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
 
LVL 69

Accepted Solution

by:
Qlemo earned 500 total points
ID: 41728493
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
 
LVL 12

Author Closing Comment

by:Dustin Saunders
ID: 41728538
Ah!  Yeah, that's the problem, good to know.  Thanks Qlemo!
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question