Solved

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

Posted on 2016-07-25
3
59 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 41

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 70

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 13

Author Closing Comment

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

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

The following article is comprised of the pearls we have garnered deploying virtualization solutions since Virtual Server 2005 and subsequent 2008 RTM+ Hyper-V in standalone and clustered environments.
A company’s centralized system that manages user data, security, and distributed resources is often a focus of criminal attention. Active Directory (AD) is no exception. In truth, it’s even more likely to be targeted due to the number of companies …
In this Micro Tutorial viewers will learn how to use Boot Corrector from Paragon Rescue Kit Free to identify and fix the boot problems of Windows 7/8/2012R2 etc. As an example is used Windows 2012R2 which lost its active partition flag (often happen…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

688 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