Solved

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

Posted on 2016-07-25
3
37 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
Comment Utility
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
Comment Utility
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
Comment Utility
Ah!  Yeah, that's the problem, good to know.  Thanks Qlemo!
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Join & Write a Comment

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
In this Micro Tutorial viewers will learn how to use Windows Server Backup to create full image of their system. Tutorial shows how to install Windows Server Backup Feature on Windows 2012R2 and how to configure scheduled Bare Metal Recovery backup.…
In this Micro Tutorial viewers will learn how to restore their server from Bare Metal Backup image created with Windows Server Backup feature. As an example Windows 2012R2 is used.

763 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

7 Experts available now in Live!

Get 1:1 Help Now