У меня есть сценарий powershell gather_objects_from_csv.ps1
, который планируется через cmd. Я использую эту команду:
powershell.exe -noexit "& 'e:\admin\gather_objects_from_csv.ps1'"
для вызова скрипта powershell, но выдает ошибку для строки в скрипте
# create an empty hash which will hold a number of smaller hashes, of member details supplied in the csv, then piped to nw_sync_employees_8.ps1
$employees_list = @{}
# import the config.xml file containing the relevant user data, username/password etc...
$config = Import-CliXML nw-config.xml
# import some detail from the "normal" Newsweaver config file
$API_user = $config["API_USER"]
$API_user_password = $config["API_PASSWORD"]
$USE_PROXY = $config["USE_PROXY"]
$verboseMode = $config["VERBOSE_MODE"]
$account_code = $config["ACCOUNT_CODE"]
$source_file = $config["CSV_PATH"]
# check to see if the source file actually exists first
if (-Not (Test-Path $source_file)) {
# if the source file can't be found, there isn't much value in continuing
Write-Host -foregroundcolor red "Could not find specified source file. Check the path, permissions or location of source file specified: " $source_file
Exit
}
# import the source file with a specified delimiter (it is a comma as it is a CSV file which is being imported)
# pipe "|" the csv to a forEach - Object loop to iterate throught the file row by row
$HashTableData = Import-CSV $source_file -Delimiter ',' |`
# ForEach - Object - iterates over each row of the csv
ForEach-Object {
# Empty hash $memberDetails, this will be populated with the information from the csv
$memberDetails = @{}
$EmployeeID = "$($_.EmployeeID)".Trim()
$FirstName = "$($_.LegalFirstName)".Trim()
$LastName = "$($_.LegalLastName)".Trim()
$LegalNameinGeneralDisplayFormat = "$($_.LegalNameinGeneralDisplayFormat)".Trim()
$LegalNameinLocalScript = "$($_.LegalNameinLocalScript)".Trim()
#set the email address as the key for the hashtable $employees_list
#and the value of this "hash of hashes" is the hash table created above ie. memberDetails (csv information)
$employees_list.Set_Item("$($Email)", $memberDetails)
}
# pass/ pipe the hash called $employees_list to the nw_sync script with the relevant parameters
$employees_list | ./nw_sync_employees.ps1 -account_code $account_code -password $API_user_password -user $API_user -permission 'All'
exit
Строка ошибки:
nw_sync_employees.ps1: The term ./nw_sync_employees.ps1' is not
recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, of if a path was included,
verify that the path is correct and try again.
+ $employee_list | ./nw_sync_employees.ps1 -account_code $account_cod...
+ ~~~~~~~~~~~~~~~~~~~
+CategoryInfo : ObjectNotFound:
(.\nw_sync_employees.ps1:String)[], CommandNotFoundException
+FullyQualifiedErrorId: CommandNotFoundException
Сценарий powershell вызывает другой скрипт ps, расположенный в той же папке. При запуске через терминал powershell тот же скрипт не выдает никакой ошибки. Но когда я пытаюсь вызвать его через командную строку, выдает ошибку.