Solved

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

Posted on 2016-07-25
3
43 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 38

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 68

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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Set OWA language and time zone in Exchange for individuals, all users or per database.
A brief introduction to what I consider to be the best editor for PowerShell.
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 tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

895 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now