“System.DefaultWorkingDirectory”一词不被识别为cmdlet的名称。

3

我正在尝试使用PowerShell在VSTS发布作业中生成CSV文件,并将其存储到当前工作目录。奇怪的是,以前相同的代码运行良好。唯一的区别是以前我使用内联脚本,但现在我使用文件路径。

最初的回答:

$results = @()

$data = 
@{                       
    uname = $uname             
    upass = "Apple@123"
    uid = $uid    
}

$results += New-Object PSObject -Property $data 

$results | export-csv -Path $(System.DefaultWorkingDirectory)\1UserTestDocument.csv -NoTypeInformation 

write-host "Print all files in the current directory :"
Get-Item *

error :

2019-03-01T06:56:19.2333832Z VERBOSE: Importing function 'CmdletHasMember'.
2019-03-01T06:56:19.2515776Z VERBOSE: Importing function 'Disconnect-AzureAndClearContext'.
2019-03-01T06:56:19.2515900Z VERBOSE: Importing function 'Initialize-AzModule'.
2019-03-01T06:56:19.2515985Z VERBOSE: Importing function 'Initialize-Azure'.
2019-03-01T06:56:19.2516046Z VERBOSE: Importing function 'Initialize-AzureRMModule'.
2019-03-01T06:56:19.2516153Z VERBOSE: Importing function 'Remove-EndpointSecrets'.
2019-03-01T06:56:19.2516240Z VERBOSE: Trying to disconnect from Azure and clear context at process scope
2019-03-01T06:56:19.2516312Z ##[command]Disconnect-AzureRmAccount -Scope Process -ErrorAction Stop
2019-03-01T06:56:19.7421197Z ##[command]Clear-AzureRmContext -Scope Process -ErrorAction Stop
2019-03-01T06:56:20.2546250Z ##[debug]Caught exception from task script.
2019-03-01T06:56:20.2796129Z ##[debug]Error record:
2019-03-01T06:56:20.2985848Z ##[debug]ForEach-Object : The term 'System.DefaultWorkingDirectory' 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.
2019-03-01T06:56:20.3038684Z ##[debug]At D:\a\_tasks\AzurePowerShell_72a1931b-effb-4d2e-8fd8-f8472a07cb62\3.1.23\AzurePowerShell.ps1:125 char:9
2019-03-01T06:56:20.3044174Z ##[debug]+         ForEach-Object {
2019-03-01T06:56:20.3217983Z ##[debug]+         ~~~~~~~~~~~~~~~~
2019-03-01T06:56:20.3218533Z ##[debug]    + CategoryInfo          : ObjectNotFound: (System.DefaultWorkingDirectory:String) [ForEach-Object], CommandNotFoun    dException
2019-03-01T06:56:20.3218704Z ##[debug]    + FullyQualifiedErrorId : CommandNotFoundException,Microsoft.PowerShell.Commands.ForEachObjectCommand

[错误] 无法识别术语'System.DefaultWorkingDirectory'作为命令、函数、脚本文件或可操作程序的名称。请检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。


"最初的回答"未提供此错误的解决方法。

您可以参考此链接:https://dev59.com/NZvga4cB1Zd3GeqP1Wm7 - SavindraSingh
没有进展,仍然出现相同的错误信息。2019-03-01T07:28:17.2933434Z ##[error]该cmdlet、函数、脚本文件或可执行程序的名称“System_DefaultWorkingDirectory”未被识别。请检查名称的拼写,或者如果包含路径,请验证路径是否正确,并重试。 - rAJ
这个调用 >> $(System.DefaultWorkingDirectory) 是特定于 Azure PowerShell 的吗?因为在标准 PowerShell 中它是不存在的... - Lee_Dailey
@Lee_Dailey 这是 VSTS 的令牌。 - 4c74356b41
@4c74356b41 - 啊!谢谢你提供的信息!我之前真的很困惑... [咧嘴笑] - Lee_Dailey
1个回答

13

要检索它,您必须使用$env:variable_name_with_underscores_instead_of_dots

在您的情况下,应该是:

$env:System_DefaultWorkingDirectory

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接