2016-11-17 1 views
0

qqq.exe가 있습니다.null이기 때문에 powershell에서 항목의 이름을 바꿀 수 없습니다

$ DB가 맞습니다. 다른 번 잘 사용합니다.

$DB = Get-Content C:\Users\asd\Desktop\Farm\AccountList.txt 
foreach ($x in $DB){ 
    Rename-Item C:\Users\asd\Desktop\Farm\$x\qqq.exe $x.exe 
} 

이름 바꾸기-항목 : null의 때문에 '을 NewName를'매개 변수 인수를 결합 할 수 없습니다. C : \ Users \ asd \ Desktop \ Farm \ test2.ps1 : 3 char : 57 + 이름 바꾸기 항목 C : \ Users \ asd \ Desktop \ Farm \ $ x \ qqq.exe $ x.exe + ~ ~~~~~ + CategoryInfo : InvalidData (:) ParameterBindingValidationException + [품목을 바꾸기] FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed, Microsoft.PowerShell.Commands.RenameItemCommand

+1

' $ x.exe' ->''$ x.exe '' –

+0

고마워! //// //// –

답변

1

파워 쉘 파서 인수가 $ 시작하여보고, 표현식으로 취급합니다. 즉 코드로 평가하려고합니다.

$x 문자열의 속성이 exe이 아니므로 표현식 결과는 $null이고 Rename-Item은 표시되는 오류를 발생시킵니다.

대신 이중 인용 문자열을 사용하는 경우, 파서는 점 이후 $x 평가를 중지합니다 :

Rename-Item C:\Users\asd\Desktop\Farm\$x\qqq.exe "$x.exe" 

Get-Help about_Parsing에서 :

When processing a command, the Windows PowerShell parser operates 
in expression mode or in argument mode: 

    - In expression mode, character string values must be contained in 
     quotation marks. Numbers not enclosed in quotation marks are treated 
     as numerical values (rather than as a series of characters). 

    - In argument mode, each value is treated as an expandable string 
     unless it begins with one of the following special characters: dollar 
     sign ($), at sign (@), single quotation mark ('), double quotation 
     mark ("), or an opening parenthesis ((). 
+0

"$ ($ x) .exe"는 향후 사용을 위해 더 적절할 것입니다 :-) – filimonic

관련 문제