检索以逗号分隔的列表,操作值并替换

时间:2019-05-10 14:16:27

标签: powershell

通过导出到csv,然后使用修改后的值将其重新摄取,我可以使用单独的命令轻松地执行此操作,但是在一个脚本中执行此操作会使我很头疼。就是因为我找不到一个可以批量替换“内存”中的值的好的资源/命令。从理论上讲,这是一个非常简单的脚本,但是缺乏PS技能,这使其变得更难。

为了更好地解释,这是与Skype命令一起使用的。

Get-CsTrustedApplicationEndpoint | select DisplayName, ApplicationId,  
      TrustedApplicationPoolFqdn, SipAddress, LineURI, DisplayNumber

将列出100多个结果,并且前两个对象需要修改。初始输出可能是

DisplayName = "InitialSharedValue UniqueValue" (or "x y z") and 
SipAddress = "sip:InitialSharedValue.UniqueValue@domain.net" (or "sip:x.y@z")

,它们需要更改为

DisplayName = "NewSharedValue UniqueValue" (or "c y z") and  
SipAddress = "sip:NewSharedValue.UniqueValue@domain.net" (or "sip:c.y@z")

基本上,x值的查找/替换将两个对象中的两个x值都替换为c。 ApplicationIdTrustedApplicationPoolFqdn也需要更改,但这可以替换为整个值。

这时,需要删除旧结果,并添加新结果。在删除旧的文件(sip的唯一值问题)之前,不能添加它们,并且在大约3分钟后要清除缓存。

通常用..

Remove-CsTrustedApplicationEndpoint  "InitialSharedValue UniqueValue"

New-CsTrustedApplicationEndpoint -SipAddress sip:NewSharedValue.UniqueValue@domain.net -DisplayName "NewSharedValue UniqueValue" -ApplicationId urn:application:NewValue -TrustedApplicationPoolFqdn NewValue.domain.net -LineURI "tel:+11234567890" -DisplayNumber 123-456-7890

在使用csv时,我使用了:

Get-CsTrustedApplicationEndpoint | select DisplayName, ApplicationId, TrustedApplicationPoolFqdn, SipAddress, LineURI, DisplayNumber | export-csv -path c:\endpoints.csv -NoTypeInformation

Import-Csv C:\endpoints.csv | foreach {Remove-CsTrustedApplicationEndpoint $_.DisplayName}

然后我在CSV中找到/替换一个值,然后

Import-Csv C:\endpoints.csv | foreach {New-CsTrustedApplicationEndpoint -SipAddress $_.SipAddress -DisplayName $_.DisplayName -ApplicationId urn:application:NewValue -TrustedApplicationPoolFqdn NewValue.domain.com -LineURI $_.LineURI -DisplayNumber $_.DisplayNumber}

就是这样。删除了旧的端点,并添加了新的端点,它们的显示名称和sipaddress稍有不同。

有一个Move-CsTrustedApplicationEdnpoint,但您不能操纵poolfqdn以外的其他任何对象。

好吧,也许这并不像我想的那么容易?我面临的挑战是进行这些修改。我可能会偶然发现删除,等待和重新添加。我一直在考虑在此过程中转储一个csv文件只是为了进行备份,所以我想我可以通过powershell作为选项使用excel修改来完成所有这些工作,而我猜呢?我认为那会有些混乱。

有什么想法吗?混乱吗?谢谢。

0 个答案:

没有答案