我正在尝试在当前目录中输出 CSV,但在与 $ComputerName 匹配的文件夹中,该文件夹已经存在。我定期为机器列表执行此操作,而不是手动将它们放在他们的文件夹中,在脚本中执行此操作会很棒。
这是当前代码,写入脚本目录。
#writing file to
[Environment]::CurrentDirectory = (Get-Location -PSProvider FileSystem).ProviderPath
Write-Host ("Saving CSV Files at " + [Environment]::CurrentDirectory + " Named the following.")
Write-Host $PritnersFilename
我尝试将 $ComputerName 添加到各个位置,但没有运气。
例子:
Write-Host ("Saving CSV Files at " + [Environment]::CurrentDirectory\$ComputerName + " Named the following.")
Write-Host ("Saving CSV Files at " + [Environment]::(CurrentDirectory\$ComputerName) + " Named the following.")
编辑: $ComputerName 是目标的变量,而不是本地主机