尝试从CSV错误“ Move-CsUser:无法绑定参数'Identity'。无法转换值...”中将用户从选择中移出。

时间:2018-09-24 06:57:04

标签: powershell skype-for-business skypedeveloper

我创建了一个Power Shell脚本供在S4B中使用...但是我已经 遇到问题,也许有人可以帮助我 问题。

我收到的错误消息如下:

Move-CsUser : Cannot bind parameter 'Identity'. Cannot convert value   {SamAccountName=Account01B}" to type
"Microsoft.Rtc.Management.AD.UserIdParameter". Error: "Cannot convert
the "@{SamAccountName=ACCOUNT01B}" value of type "Se
lected.System.Management.Automation.PSCustomObject" to type
"Microsoft.Rtc.Management.AD.UserIdParameter"." At line:25 char:27
+     Move-CsUser -Identity $Fullname -Target pool101.test.se -Confirm:false
+                           ~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Move-CsUser],  ParameterBindingException
    + FullyQualifiedErrorId : nnotConvertArgumentNoMessage,Microsoft.Rtc.Management.AD.Cmdlets.MoveOcsUserCmdlet

不仅如此,看起来FOREACH也没有循环播放...

脚本如下:

# Exporting out Data to CSV file
$CurrentDate = Get-Date
$CurrentDate = $CurrentDate.ToString('yyyy-MM-dd_hh-mm-ss')
Get-CsUser | Where-Object {$_.RegistrarPool -match "Pool101.test.se" -and
$_.ConferencingPolicy -notmatch "AllowInMeetings"} | Select-Object
SamAccountName | Export-Csv -Path "C:\Temp
\Change_Call_Policy_access_Users_$CurrentDate.csv" -NoTypeInformation

#Variables
File = Get-Content "C:\Temp\Change_Call_Policy_access_Users_$CurrentDate.csv"
Log = New-Item -ItemType File -Path "C:\Temp\changed_users_log.txt" -Force

#Import csv
usercsv = Import-Csv -path $file -Delimiter ','
Check if user file is empty.
if ($Usercsv -eq $null)
{
    Add-Content $Log -Value "$($CurrentDate) No Users Found in the Input File      
    change_Call_Policy_access_Users_$CurrentDate.csv"
    exit 0
}

在UserCSV中检查以'[n-z5-9]$'结尾的SamAccountName

ForEach ($user in $usercsv) 
{
    $Fullname = $usercsv | Where-Object {$_.SamAccountName -match '[n-z5-9]$'} |  
    Select-Object SamAccountName -ErrorAction SilentlyContinue

    Move-CsUser -Identity $Fullname -Target pool02.test.se -Confirm:false
    Add-Content -Path $Log -Value "$($FullName) not enabled.  $(Get-
    Date)$($error[0])"

    Write-Host "Change users from CSV completed!"
    Write-Host ""
    Write-Host ""
    Write-Host ""
}
Move-Item -Path $File -Destination C:\Temp\Archive
update-csuserdatabase -verbose
sleep -seconds 30

1 个答案:

答案 0 :(得分:0)

我确实解决了这个问题,它缺少一个$ ...

//指甲