Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

error while adding user in local policy

$
0
0

Hi,

 

Below is my script to add user into local policy using powershell script:

#*********************************

 

AddUserRights

 

Function AddUserRights 

    { Param(

[Parameter(Mandatory=$True)][ValidateNotNullOrEmpty()]

[String]$serviceaccname

 ) 

        $RightsFailed =  $false 

        NTRights.Exe -u $serviceaccname +r SeLockMemoryPrivilege 

 

        If (!$?) 

            { 

                $RightsFailed =  $true 

                Write-Host "`tFailed to add user rights for $serviceaccname`n`tSee:" -ForegroundColor "yellow" -NoNewline 

                ($ElapsedTime.Elapsed.ToString())+ "[WARN]      Failed to add user rights for ${serviceaccname}: 'Lock pages in memory', 'Generate security audits'" 

                Return $RightsFailed 

            } 

 

        NTRights.Exe -u $serviceaccname +r SeManageVolumePrivilege 

        If (!$?) 

            { 

                $RightsFailed =  $true 

                Write-Host "`tFailed to add user rights for $serviceaccname`n`tSee " -ForegroundColor "yellow" -NoNewline 

                ($ElapsedTime.Elapsed.ToString())+ "[WARN]      Failed to add user rights for ${serviceaccname}: 'Perform volume maintenance tasks', 'Generate security audits'" 

                Return $RightsFailed 

            }  

        Else 

            { 

                GPUpdate /Force 

                $RightsFailed = $false 

                Write-Host "`tSuccess" -ForegroundColor "green"  

                ($ElapsedTime.Elapsed.ToString())+" [INFO]      User rights 'Lock pages in memory & Perform volume maintenance tasks', 'Generate security audits' added for $serviceaccname"  

            } 

 

            Return $RightsFailed 

    } 

#*************************

 

But I am getting error as"

NTRights.Exe : The term 'NTRights.Exe' is not recognized as the name of a cmdlet, function, script file, or operable program. 

Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

At C:\Program Files\Add_Account_To_v1.ps1:13 char:9

+         NTRights.Exe -u $serviceaccname +r SeLockMemoryPrivilege

+         ~~~~~~~~~~~~

    + CategoryInfo          : ObjectNotFound: (NTRights.Exe:String) [], CommandNotFoundException

    + FullyQualifiedErrorId : CommandNotFoundException

 

Please help me to resolve this error.


Viewing all articles
Browse latest Browse all 6937

Trending Articles