User profile "access denied" for task scheduler job

Lazy Bee 0 Reputation points
2024-04-09T10:13:19.09+00:00

We have some Task scheduler jobs configured on Windows server (OS 2016). Few jobs were configured with "XYZ" service account and it's password. This particular user profile was taking a lot of space which is abnormal. The user profile cleanup was performed to free up the space in C drive. Based on our analysis, after the cleanup, the value of the argument "password" is being passed as "null". The jobs which are running using the account is throwing error mentioning "Access is denied". Please provide us any solution.

Error Example from 3 different jobs-

An error has occurred while connecting to the SharePoint Online site. Aborting...

Connect-PnPOnline : Access is denied

At D:****\GetAllUsersProfiles_AllProps.ps1:111 char:5

  • Connect-PnPOnline -Url $spSiteUrl -Credentials $Cred
    
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:) [Connect-PnPOnline], Win32Exception
    • FullyQualifiedErrorId : System.ComponentModel.Win32Exception,PnP.PowerShell.Commands.Base.C
    onnectOnline

7:11


An error has occurred while establishing a connection with target site. | Error |

2024-04-08 09:23:02.5082 | New-Object : Exception calling ".ctor" with "2" argument(s): "Cannot process argument because the

value of argument "password" is null. Change the value of argument "password" to a non-null

value."

At D:****\Utils.ps1:41 char:13

  • $cred = New-Object -TypeName System.Management.Automation.PSCrede ...
    
  •         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException
    • FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewO
    bjectCommand

| Error |

7:13


2024-04-05 13:51:26.0172|Error: System.Management.Automation.PSInvalidOperationException: Unable to connect using provided arguments

at PnP.PowerShell.Commands.Base.ConnectOnline.Connect(CancellationToken& cancellationToken)

at PnP.PowerShell.Commands.Base.ConnectOnline.ProcessRecord()

at System.Management.Automation.CommandProcessor.ProcessRecord()

2024-04-05 13:51:26.0640|*******Total Execution Time is @{Days=0; Hours=0; Minutes=6; Seconds=47} ******

2024-04-05 13:51:26.2359|************ Sync process Completed at 04/05/2024 13:51:26 local time ************

2024-04-05 13:51:32.1370|************ Sync process started at 04/05/2024 13:51:32 local time ************

2024-04-08 12:47:34.0074|Error: System.Management.Automation.PSInvalidOperationException: Unable to connect using provided arguments

at PnP.PowerShell.Commands.Base.ConnectOnline.Connect(CancellationToken& cancellationToken)

at PnP.PowerShell.Commands.Base.ConnectOnline.ProcessRecord()

at System.Management.Automation.CommandProcessor.ProcessRecord()

2024-04-08 12:47:43.3064|************ Sync process started at 04/08/2024 12:47:43 local time ************

Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
13,102 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MotoX80 33,826 Reputation points
    2024-04-09T14:23:58.0266667+00:00

    the value of the argument "password" is being passed as "null".

    Where is the script getting the password from? A file? Hardcoded in the script?

    If you want to use the userid+password that's been configured in the task, then don't use a credential object.

    Here is an example of using a credential object in a script. The account is named admin and its password is also admin.

    $script = 
     {
        "This script is running on {0}" -f $env:COMPUTERNAME
        ""
        "**** Calling whoami to execute on the remote system"
        c:\Windows\system32\whoami.exe
     }
     $User = ".\admin"
     $PWord = ConvertTo-SecureString -String "admin" -AsPlainText -Force
     $Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord
     Invoke-Command -ComputerName "test10b" -credential $Credential -ScriptBlock $script 
    
     
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.