I am trying to import Catalog Models and it seems that it doesn't like certain characters.
Powershell isn't my background ( prefer C# etc..) but I'm needing to escape characters that are in a csv such as
CSV file
Header below (Model)
Model
Intel(R) Xeon(R)
CPU X5670 @ 2.93GHz |
Now this CSV file only has 1 column with the header of "Model"
I noticed that certain keywords are mandatory - I don't know which ones, but it seems that Ordinal is required so i set that to always be a "1"
How can I escape any characters that are causing errors ( or @ ?
Add-SCSMEnumeration -Parent $enum -Name ($enum.Name + "." + $t.Model.Replace(' ','')) -DisplayName $t.Model -Ordinal 1 -ManagementPack $mp
My Powershell which imports 4 records and choked on the one above
"Intel(R) Xeon(R) CPU X5670 @ 2.93GHz "
|
Import-Module smlets
$mpName = "CompanyName.ListValues.HWA.CatalogModels"
$enum = Get-SCSMEnumeration -Name Cireson.AssetManagement.CatalogItemModelEnum$
$types = Import-Csv -Path "E:\AssetFiles\Models.csv"
$mp = New-SCSMManagementPack -ManagementPackName $mpName -FriendlyName $mpName -DisplayName $mpName -PassThru
foreach ($t in $types) {
#$parent = Get-SCSMEnumeration | ?{$_.name -eq ($enum.Name + "." + $t.Parent.Replace(' ',''))}
#if ($parent) {
#Add-SCSMEnumeration -Parent $enum -Name ($enum.Name + "." + $t.Model.Replace(' ','')) -DisplayName $t.Model -Ordinal 1 -ManagementPack $mp
Add-SCSMEnumeration -Parent $enum -Name ($enum.Name + "." + $t.Model.Replace(' ','')) -DisplayName $t.Model -Ordinal 1 -ManagementPack $mp
}
Answers
Add-SCSMEnumeration -Parent $enum -Name ($enum.Name + "." + $t.Model.Replace(' ','').Replace('@','').Replace('(','').Replace(')','')) -DisplayName $t.Model -Ordinal 1 -ManagementPack $mp