Je suis en train d'ajouter 400 ordinateur à une collection et j'ai une erreur en cours d'exécution du powershell dans SCCM. J'essaie de changer le. à _ mais rencontre aussi la même erreur.Impossible d'ajouter le fichier txt des ordinateurs dans la collection SCCM
Method invocation failed because [System.Char] does not contain a method named 'Split'.
At line:8 char:5
+ $collectionname = $filenames.Name[$x].Split(".")[0]
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Powershell:
#Set path to collection directory
$collectiondir = "D:\Collections\"
#Pull only .TXT files into array
$filenames = Get-ChildItem $collectiondir* -include *.txt
for ($x=0; $x -lt ($filenames.Length); $x++) {
$collectionname = $filenames.Name[$x].Split(".")[0]
$collectionname
#Add new collection based on the file name
try {
New-CMDeviceCollection -Name $collectionname -LimitingCollectionName "All Systems"
}
catch {
"Error creating collection - collection may already exist: $collectionname" | Out-File "$collectiondir\$collectionname`_invalid.log" -Append
}
#Read list of computers from the text file
$computers = Get-Content $filenames[$x]
foreach($computer in $computers) {
try {
Add-CMDeviceCollectionDirectMembershipRule -CollectionName $collectionname -ResourceId $(get-cmdevice -Name $computer).ResourceID
}
catch {
"Invalid client or direct membership rule may already exist: $computer" | Out-File "$collectiondir\$collectionname`_invalid.log" -Append
}
}
}
Si vous voulez avoir ce maladroit pour , changez l'index juste derrière '$ filenames [$ x] .Name.Split (". ") [0]' Mais je préférerais un simple 'foreach ($ filename dans $ noms de fichiers) {' – LotPings
Merci, mais je toujours obtenez le même message d'erreur. Si je devais utiliser le plus simple, j'obtiendrais l'erreur. 'Get-Content: Impossible de lier l'argument au paramètre 'Path' car il est nul. À la ligne: 19 char: 30 + $ computers = Obtenir-Contenu $ noms de fichiers [$ x] + ~~~~~~~~~~~~~~ + CatégorieInfo: InvalidData: (:) [Get- Content], ParameterBindingValidationException + FullyQualifiedErrorId: ParameterArgumentValidationErrorNullNotAllowed, Microsoft.PowerShell.Commands.GetContentCommand' –