我正在尝试编写一个 PowerShell 脚本,该脚本将读取包含组列表和这些组的相关信息的 CSV 文件,然后将它们写入注册表文件(说来话长)。我最初将此信息硬编码到 PowerShell 脚本中,但这使得编辑和添加组变得困难,所以我选择了 csv 文件。该脚本在 PowerShell ISE 中运行良好,但当我尝试使用我制作的 .cmd 文件启动它以确保权限正确时,PowerShell 脚本不再能够从 csv 文件中提取信息。我检查了一下,它只提取“未定义”的默认值
$script:org1 = 'undefined'
$script:org2 = 'undefined'
$script:org3 = 'undefined'
$script:prefix = 'undefined'
$script:baselinetag = 'Standard'
$script:path1 = "HKLM:\Software\WOW6432Node\BigFix\EnterpriseClient\Settings\Client\Organization 1"
$script:path2 = "HKLM:\Software\WOW6432Node\BigFix\EnterpriseClient\Settings\Client\Organization 2"
$script:path3 = "HKLM:\Software\WOW6432Node\BigFix\EnterpriseClient\Settings\Client\Organization 3"
#finds current path and then parent directory to access depts csv file
$scriptPath = (Get-Location)
$ParentPath = Split-Path -Path $scriptPath
$CSVPath = $parentPath + "\Depts.csv"
#displays ID # and dept name
$csv = Import-CSV -path $CSVPath
$nameNumber = $csv|Select-Object "ID #","Dept Name"
#Write-Host ($nameNumber -join "`n")
$count = 0
$max = $csv.length +1
while($count -ne $max){
read-Host $csv[$count].'ID #' $csv[$count].'Dept Name'
$count++
}
$ID = Read-Host -Prompt 'Select ID # for the department from the above list '
$script:org1 = $csv[$ID].Org1
$script:org2 = $csv[$ID].Org2
$script:org3 = $csv[$ID].Org3
$script:prefix = $csv[$ID].Prefix
$script:baselinetag = $csv[$ID].Baseline