Hello,
I will try to be has clear as possible, as English is not my mother tongue.
I have 2 scripts, one calling the other one.
The first (the one which is called) is doing a call to a rest api to get some informations from our Issue Managing System.
The second script is doing many stuffs regarding account creation, with a GUI, so I'll not post all the code here.
Here are the samples :
Script 1 (which is working when used directly using powershell on a Windows 2012 R2 ):
$cpt = 0 $results = Invoke-RestMethod -uri $uri -Headers $headers -ContentType "application/json" foreach ($result in $results.issues) { ## Recherche du manager dans ActiveDirectory sans utiliser le module Active Directory $Manager = $result.fields.customfield_10503.name $root = [ADSI]'' $searcher = new-object System.DirectoryServices.DirectorySearcher($root) $searcher.filter = "(&(objectClass=user)(sAMAccountName=$Manager))" $user = $searcher.findall() ##Affichage de principe pour voir ce que l'on trouve Write-Host "`n" Write-Host "Ticket CSI : $($result.key)" Write-Host "Interne ou Presta ? : $($result.fields.issuetype.name)" Write-Host "Manager : $($result.fields.customfield_10503.name)" Write-Host "Login trouv dans l'AD : $($user.properties.samaccountname)" Write-Host "Prnom : $($result.fields.customfield_10495)" Write-Host "Nom : $($result.fields.customfield_10494)" Write-Host "Fonction : $($result.fields.customfield_10502)" Write-Host "Socit : $($result.fields.customfield_10535.value)" Write-Host "Service : $($result.fields.customfield_16244.value)" Write-Host "Service bis : $($result.fields.customfield_16244.child.value)" Write-Host "Site : $($result.fields.customfield_10453.value)" Write-host "Date de fin de contrat : $($Result.fields.customfield_10501)" Write-Host "Type de contrat : $($result.fields.customfield_10498.value)" Write-Host "Site : $($result.fields.customfield_11441.value)" }
return $results (#used only when I am calling it from the second script)
The result is like this when executed directly (there are many results) :
Ticket CSI : TicketNumber
Interne ou Presta ? : Arrive Interne
Manager : Login_Login
Login trouv dans l'AD : Login_Login
Prnom : Frdric
Nom : XXXXXXXXXX
Fonction : Intitul du poste
Socit : XXXXXXXXXX
Service : XXXXXXXXXX
Service bis : XXXXXXXXXX
Site : XXXXXXXXXX
Date de fin de contrat : 2015-08-28
Type de contrat : CDD
Site : XXXXXXXXXX
Script 2 (it is executed from the Exchange Management Shell for Exchange 2010, on the same server, so from a PS V2 version, that is why I need to start a new powershell session, to have the JIRA_CONNECTION.ps1 working because of theInvoke-RestMethod :
$temps = powershell.exe -file D:\SCRIPTS\JIRA_Connection\JIRA_CONNECTION.ps1 write-host "t0" $temps foreach ($result in $temps.issues ) { ## Recherche du manager dans ActiveDirectory sans utiliser le module Active Directory $Manager = $result.fields.customfield_10503.name $root = [ADSI]'' $searcher = new-object System.DirectoryServices.DirectorySearcher($root) $searcher.filter = "(&(objectClass=user)(sAMAccountName=$Manager))" $user = $searcher.findall() ## Affichage de principe pour voir ce que l'on trouve Write-Host "`n" Write-Host "Ticket CSI : $($result.key)" Write-Host "Interne ou Presta ? : $($result.fields.issuetype.name)" Write-Host "Manager : $($result.fields.customfield_10503.name)" Write-Host "Login trouv dans l'AD : $($user.properties.samaccountname)" Write-Host "Prnom : $($result.fields.customfield_10495)" Write-Host "Nom : $($result.fields.customfield_10494)" Write-Host "Fonction : $($result.fields.customfield_10502)" Write-Host "Socit : $($result.fields.customfield_10535.value)" Write-Host "Service : $($result.fields.customfield_16244.value)" Write-Host "Service bis : $($result.fields.customfield_16244.child.value)" Write-Host "Site : $($result.fields.customfield_10453.value)" Write-host "Date de fin de contrat : $($Result.fields.customfield_10501)" Write-Host "Type de contrat : $($result.fields.customfield_10498.value)" }
The result of the execution is looking like that :
t0
expand : schema,names
startAt : 0
maxResults : 50
total : 11
issues : {@{expand=operations,editmeta,changelog,transitions,renderedFields; id=266037; self=https://servicedesk.vsct.fr/rest/api/2/issue/266037; key=ADVII-65;
fields=}, @{expand=operations,editmeta,changelog,transitions,renderedFields; id=265450; self=https://servicedesk.vsct.fr/rest/api/2/issue/265450;
key=ADVII-57; fields=}, @{expand=operations,editmeta,changelog,transitions,renderedFields; id=264907;
self=https://servicedesk.vsct.fr/rest/api/2/issue/264907; key=ADVII-52; fields=}, @{expand=operations,editmeta,changelog,transitions,renderedFields;
id=264899; self=https://servicedesk.vsct.fr/rest/api/2/issue/264899; key=ADVII-51; fields=}...}
Ticket CSI :
Interne ou Presta ? :
Manager :
Login trouv dans l'AD :
Prnom :
Nom :
Fonction :
Socit :
Service :
Service bis :
Site :
Date de fin de contrat :
Type de contrat :
All the fields are empty and it only display once when entering in the foreach.
Just to compare, here is the result when I display $ Results from the first script
@{expand=schema,names; startAt=0; maxResults=50; total=11; issues=System.Object[]}
expand : schema,names
startAt : 0
maxResults : 50
total : 11
issues : {@{expand=operations,editmeta,changelog,transitions,renderedFields; id=266037;
self=https://servicedesk.vsct.fr/rest/api/2/issue/266037; key=ADVII-65; fields=},
@{expand=operations,editmeta,changelog,transitions,renderedFields; id=265450;
self=https://servicedesk.vsct.fr/rest/api/2/issue/265450; key=ADVII-57; fields=},
@{expand=operations,editmeta,changelog,transitions,renderedFields; id=264907;
self=https://servicedesk.vsct.fr/rest/api/2/issue/264907; key=ADVII-52; fields=},
@{expand=operations,editmeta,changelog,transitions,renderedFields; id=264899;
self=https://servicedesk.vsct.fr/rest/api/2/issue/264899; key=ADVII-51; fields=}...}
I don't know what i am missing, or if that is just impossible to do this...
What i have noticed is the fact that the issues array, when it is returned to the calling script, it displays like if it was just a string instead of an array.
I you look well, there is always a Return which make the lines starts with {@{expand=, when i am using the script from the V3 PS version, which seems to not be the case when it is returned...
Thanks in advance for your help.
Pierre-Yves