none
Get-ADUSer as JOB ? RRS feed

  • Question

  • Hello

    i am using WinPE with imported module for AD and i would like to check for ADUser as the background job. I can connect and retrieve data using get-aduser without any issues, but start-job doesnt return anything . The script i am using is : 

    $FQDN = 'contoso.com'
    
    	$AdminAccount = 'Contoso\Administrator'
    	$AdminPassword = 'P@ssw0rd'
    
    	$SecurePassword = New-Object -TypeName System.Security.SecureString
    	$AdminPassword.ToCharArray() | ForEach-Object { $SecurePassword.AppendChar($_) }	
    	$script:credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist $AdminAccount, $SecurePassword
    	
    $job = {
    		
    		(Get-ADUser -filter { (Name -eq 'test') -or (SamAccountName -eq 'test') -or (UserPrincipalName -eq 'test') } -AuthType Negotiate -credential $credentials -Server Test-server.contoso.com).DistinguishedName
    
    	}

    So in this case, i tried 2 things : 

    Start-job -name 'test' -scriptblock $job

    This command starts the job, but during receive-job  i am presented with credential window for LOCALHOST, that actually does not return any data.

    second case i can use is : 

    start-job -name 'test' -scriptblock $job -credential $credentials

    in this case, when i check the status via get-job, i see status as blocked. The error is :specified service is not installed - as it tries to register job for LOCALHOST again. 

    I cannot use invoke-command, as this is not part of WInPE. 

    Any thoughts ? 


    • Edited by Daniel Kusnir Friday, January 26, 2018 1:26 PM forgot one piece of code
    • Moved by Bill_Stewart Monday, March 12, 2018 9:03 PM User answered own question
    Friday, January 26, 2018 1:25 PM

All replies

  • I don't believe the job module is part of PE.  Post in the PE forum for more information.

    Also not that jobs cannot use variables define outside of the job.


    \_(ツ)_/

    Friday, January 26, 2018 6:00 PM
  • You are correct.

    I figured it out .The problem was the outside variables. i just changed the variable :

    (Get-ADUser -filter { (Name -eq 'test') -or (SamAccountName -eq 'test') -or (UserPrincipalName -eq 'test') } -AuthType Negotiate -credential $using:credentials -Server $using:testserver).DistinguishedName
    

    now its all working 

    Friday, January 26, 2018 9:31 PM