Link to home
Start Free TrialLog in
Avatar of Chewe Chileshe
Chewe ChilesheFlag for Zambia

asked on

I am getting errors when running a powershell script from the command prompt

I trying to run a powershell script on Windows Server 2012 R2 using psexec and I am getting an error about a missing delimiter. The following is the error message I am getting:

The string is missing the terminator: ".
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordEx
   ception
    + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString



I am running the script using the following command:

psexec -s -i powershell -noexit “& ‘E:\Permissions.ps1′”

and the following is the script I am running:

====copy from here ====

#ChangePermissions.ps1
# CACLS rights are usually
# F = FullControl
# C = Change
# R = Readonly
# W = Write

$StartingDir= "E:\local"

$Principal="company\user"

$Permission="F"

$Verify=Read-Host `n "You are about to change permissions on all" `
"files starting at"$StartingDir.ToUpper() `n "for security"`
"principal"$Principal.ToUpper() `
"with new right of"$Permission.ToUpper()"."`n `
"Do you want to continue? [Y,N]"

if ($Verify -eq "Y") {

foreach ($file in $(Get-ChildItem $StartingDir -recurse)) {
#display filename and old permissions
write-Host -foregroundcolor Yellow $file.FullName
#uncomment if you want to see old permissions
#CACLS $file.FullName

#ADD new permission with CACLS
CACLS $file.FullName /E /P "${Principal}:${Permission}" >$NULL

#display new permissions
Write-Host -foregroundcolor Green "New Permissions"
CACLS $file.FullName
}
}
===== to here======


Thanks team.
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

Does the server have an E: drive and is the script located on that drive?
psexec -s -i powershell -noexit “& ‘E:\Permissions.ps1′”

you didn't say what computer to run it on
psexex  \\computername -s -i powershell.exe -file e:\permissions.ps1


#ChangePermissions.ps1
# CACLS rights are usually
# F = FullControl
# C = Change
# R = Readonly
# W = Write

$StartingDir= "E:\local"

$Principal="company\user"

$Permission="F"

$Verify=Read-Host `n "You are about to change permissions on all" `
"files starting at"$StartingDir.ToUpper() `n "for security"`
"principal"$Principal.ToUpper() `
"with new right of"$Permission.ToUpper()"."`n `
"Do you want to continue? [Y,N]"

if ($Verify -eq "Y") {

foreach ($file in $(Get-ChildItem $StartingDir -recurse)) {
#display filename and old permissions
write-Host -foregroundcolor Yellow $file.FullName
#uncomment if you want to see old permissions
#CACLS $file.FullName
#ADD new permission with CACLS
CACLS $file.FullName /E /P "${Principal}:${Permission}" >$NULL
#display new permissions
Write-Host -foregroundcolor Green "New Permissions"
CACLS $file.FullName
}
}

Open in new window

Avatar of Chewe Chileshe

ASKER

Hi,

Its running on the local machine, yes it does have an drive.

Regards
you don't need psexec to run something on the local machine.. the machine name is still needed though
Hello,

I ran it with the computer name added and I got exactly the same error.

Thanks,

Chewe
I have ran this script before successfully, I suspect that something is missing or was accidentally added to the script itself. The error message says that a terminator is missing
This problem appears to be in the command that I am using to launch the script. I ran it with an invalid script name and got exactly the same error
ASKER CERTIFIED SOLUTION
Avatar of Chewe Chileshe
Chewe Chileshe
Flag of Zambia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Accept: 'Chewe Chileshe' (https:#a43198983)

If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

seth2740
Experts-Exchange Cleanup Volunteer