Bonjour

J'ai créé ce script pour déployer autocad sur des PC à distance.

Problème lors de l'envoi de la commande
Code PowerShell : Sélectionner tout - Visualiser dans une fenêtre à part
Invoke-Command -Session $Session -ScriptBlock { Start-Process -FilePath $Exe -ArgumentList "`'$Argument`'" }
Powershell m'insulte disant que l'argument -FilePath est null.
Je ne comprend pas auriez vous une piste à me donner ?

Merci

J'ai fais un test en remplaçant les variables par les valeurs en dur et sa fonctionne ???
Code PowerShell : Sélectionner tout - Visualiser dans une fenêtre à part
Invoke-Command -Session $Session -ScriptBlock { Start-Process -FilePath 'C:\Temp\AutocadLT2019\Img\Setup.exe' -ArgumentList '/W /q /I C:\Temp\AutocadLT2019\Img\AUTOCAD LT 2019.ini /language fr-fr' -Wait}

Code PowerShell : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
Clear-Host
 
[Guid]$Key = "aaaa-dddd-xxxx-xxxx-11111111111"
$ScriptPath = (Split-Path -parent $MyInvocation.MyCommand.Definition) 
$CredFile = "CredData.ps1xml"
[Object]$CredData = Import-CliXml -Path ($ScriptPath + "\" + $CredFile)
 
if ( $? ) {
	$SecurePassword = ConvertTo-SecureString -String $CredData.SecurePassword -Key $Key.ToByteArray()
	$UPN = $CredData.UserName
	$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList ($UPN, $SecurePassword)
} else {
	Write-Warning "Impossible de récupérer les identifiants de connexion."
	return
}
 
$Depot = '\\NAS\depot\AUTOCAD\2019\AUTOCAD LT 2019\Img'
$WorkdirTEMP = 'C:\Windows\Temp\AutocadLT2019\Img\'
[String]$Exe ="$($WorkdirTEMP)Setup.exe"
[string]$Argument = "/W /q /I $($WorkdirTEMP)AUTOCAD LT 2019.ini /language fr-fr"
$MsiID = '{28B89EEF-2009-040C-1102-CF3F3A09B77D}'
 
# Pour Chaque Ordinateur
foreach ($ComputerMember in (Get-ADGroupMember "DEPLOY - AUTOCAD LT 2019")) {
 
	Write-Host $(Get-Date -Format "dd/MM/yyyy hh:mm:ss") "Computer : " $ComputerMember.Name
 
	# Si on peut ce connecter à l'ordinateur distant alors on effectue le traitement
	If (-not (Test-WSMan $ComputerMember.Name -ErrorAction SilentlyContinue )) {
 
		Write-Warning $(Get-Date -Format "dd/MM/yyyy hh:mm:ss") "Pas de connexion WinRM"
 
	} else {
 
		# Connexion a la session distante
		$Session = New-PSSession -ComputerName $ComputerMember.Name -Credential $Credential
 
		# Vérifier si programme deja installé
		$ProgIsIntalled = Get-WmiObject -Query "SELECT IdentifyingNumber FROM Win32_Product WHERE IdentifyingNumber=`'$MsiID`'" -ComputerName $ComputerMember.Name -Credential $Cred
 
		if ( -not $ProgIsIntalled ) {
 
			Write-Host $(Get-Date -Format "dd/MM/yyyy hh:mm:ss") "Depot = " $Depot
			Write-Host $(Get-Date -Format "dd/MM/yyyy hh:mm:ss") "Destination = " $WorkdirTEMP.Replace($WorkdirTEMP.Substring(0,2), "\\"+$ComputerMember.Name+"\"+$WorkdirTEMP.Substring(0,1)+"$")
			Write-Host $(Get-Date -Format "dd/MM/yyyy hh:mm:ss") "Début du Transfert..."
 
			# Transfere des sources
			Copy-Item -Path $Depot -Destination $WorkdirTEMP.Replace($WorkdirTEMP.Substring(0,2), "\\"+$ComputerMember.Name+"\"+$WorkdirTEMP.Substring(0,1)+"$") -Force -Recurse
 
			Write-Host $(Get-Date -Format "dd/MM/yyyy hh:mm:ss") "Fin du Transfert."
 
			Write-Host $(Get-Date -Format "dd/MM/yyyy hh:mm:ss") $Exe "`'$Argument`'"
			Write-Host $(Get-Date -Format "dd/MM/yyyy hh:mm:ss") "Execution de l'installation..."
 
			# Execution de l'installation sur le PC distant
			Invoke-Command -Session $Session -ScriptBlock { Start-Process -FilePath $Exe -ArgumentList "`'$Argument`'" }
 
			# Supprimer les fichiers apres installation
			# Remove-Item -Path "C:\Windows\Temp\AutocadLT2019" -Force -Recurse
 
		} else {
			Write-Host "Le programme est déjà installé."
		}
 
		Remove-PSSession -Session $Session
	}
}