Powershell - Bulk Import from a csv file Set user DID

%3CLINGO-SUB%20id%3D%22lingo-sub-2594071%22%20slang%3D%22en-US%22%3EPowershell%20-%20Bulk%20Import%20from%20a%20csv%20file%20Set%20user%20DID%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2594071%22%20slang%3D%22en-US%22%3E%3CP%3EHello%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20want%20to%20make%20a%20script%20where%20i%20can%20import%20a%20.csv%20file%20with%20multiple%20users%20and%20numbers.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20original%20script%20is%3D%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3E%20Set-CsUser%20-ID%20a.user%40domain.com%20-OnPremLineURI%20tel%3A%2B31881234567%20-EnterpriseVoiceEnabled%20%24true%20-HostedVoiceMail%20%24true%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20tried%20to%20make%20a%20script%2C%20but%20it%20fails%20on%3A%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3ECannot%20bind%20parameter%20'Identity'.%20Cannot%20convert%20value%20%22System.Collections.Hashtable%22%20to%20type%20%22Microsoft.Rtc.Management.AD.UserIdParameter%22.%20Error%3A%20%22Cannot%20convert%20hashtable%20to%20an%20object%20of%20the%20following%20type%3A%20Microsoft.Rtc.Management.AD.UserIdParameter.%20Ha%0Ashtable-to-Object%20conversion%20is%20not%20supported%20in%20restricted%20language%20mode%20or%20a%20Data%20section.%22%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20Script%20i%20tried%20to%20use%20is%20(I%20find%20one%20online%20and%20edit%20the%20script)%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3EImport-Csv%20C%3A%5Cpath%5Cfile.csv%20-Delimiter%20'%3B'%0A%20%20%20%20ForEach-Object%7B%0A%20%20%20%20%20%20%20%20%24paramsetcsuser%20%3D%20%40%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20Identity%20%3D%20%24_.identity%0A%20%20%20%20%20%20%20%20%20%20%20%20EnterpriseVoiceEnabled%20%3D%20if(%24_.EnterpriseVoiceEnabled%20-eq%20'true')%7B%24true%7Delse%7B%24false%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20HostedVoiceMail%20%3D%20if(%24_.HostedVoiceMail%20-eq%20'true')%7B%24true%7Delse%7B%24false%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20OnPremLineURI%20%3D%20'tel%3A'%20%2B%20%24_.OnPremLineURI%0A%20%20%20%20%20%20%20%20%20%20%20%20UnknownParameter5%20%3D%20'%2B'%0A%20%20%20%20%20%20%20%20%20%20%20%20UnknownParameter6%20%3D%20%24_.OnPremLineURI%0A%20%20%20%20%20%20%20%20%7D%0ASet-CsUser%20%24paramsetcsuser%0A%7D%0A%0A%20%20%20%20%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ecsv%20file%20i%20use%3A%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Vincent_Holthuizen_0-1627481362964.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F299031i300E251F711BD766%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Vincent_Holthuizen_0-1627481362964.png%22%20alt%3D%22Vincent_Holthuizen_0-1627481362964.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIs%20there%20anyone%20that%20can%20help%20me%20with%20this%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2594071%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2594098%22%20slang%3D%22en-US%22%3ERE%3A%20Powershell%20-%20Bulk%20Import%20from%20a%20csv%20file%20Set%20user%20DID%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2594098%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F72542%22%20target%3D%22_blank%22%3E%40adam%20deltinger%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIam%20using%20the%20MicrosoftTeams%20module%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3ESet-ExecutionPolicy%20unrestricted%0AInstall-Module%20MicrosoftTeams%20-Force%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3EImport-Module%20-Name%20MicrosoftTeams%0A%20%0A%23Connect%20to%20Microsoft%20Teams%0AConnect-MicrosoftTeams%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2594094%22%20slang%3D%22en-US%22%3ERE%3A%20Powershell%20-%20Bulk%20Import%20from%20a%20csv%20file%20Set%20user%20DID%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2594094%22%20slang%3D%22en-US%22%3EWhat%20powershell%20module%20are%20you%20using%3F%3C%2FLINGO-BODY%3E
New Contributor

Hello,

 

I want to make a script where i can import a .csv file with multiple users and numbers.

 

The original script is= 

 

 

 Set-CsUser -ID a.user@domain.com -OnPremLineURI tel:+31881234567 -EnterpriseVoiceEnabled $true -HostedVoiceMail $true

 

 

 

I tried to make a script, but it fails on: 

 

 

Cannot bind parameter 'Identity'. Cannot convert value "System.Collections.Hashtable" to type "Microsoft.Rtc.Management.AD.UserIdParameter". Error: "Cannot convert hashtable to an object of the following type: Microsoft.Rtc.Management.AD.UserIdParameter. Ha
shtable-to-Object conversion is not supported in restricted language mode or a Data section."

 

 

 

The Script i tried to use is (I find one online and edit the script):

 

 

Import-Csv C:\path\file.csv -Delimiter ';'
    ForEach-Object{
        $paramsetcsuser = @{
            Identity = $_.identity
            EnterpriseVoiceEnabled = if($_.EnterpriseVoiceEnabled -eq 'true'){$true}else{$false}
            HostedVoiceMail = if($_.HostedVoiceMail -eq 'true'){$true}else{$false}
            OnPremLineURI = 'tel:' + $_.OnPremLineURI
            UnknownParameter5 = '+'
            UnknownParameter6 = $_.OnPremLineURI
        }
Set-CsUser $paramsetcsuser
}

    

 

 

 

csv file i use:

Vincent_Holthuizen_0-1627481362964.png

 

 

Is there anyone that can help me with this?

 

2 Replies
What powershell module are you using?

@adam deltinger 

Iam using the MicrosoftTeams module

 

Set-ExecutionPolicy unrestricted
Install-Module MicrosoftTeams -Force

 

Import-Module -Name MicrosoftTeams
 
#Connect to Microsoft Teams
Connect-MicrosoftTeams