在Windows Server 2008 R2上的PowerShell中创建专用队列

时间:2015-11-19 15:08:56

标签: windows powershell server windows-server-2008-r2

我用谷歌搜索了如何做到这一点,我发现了这段代码:

Write-Host "... create a new queue"
$q1 = [System.Messaging.MessageQueue]::Create(".\private$\myqueues")

Write-Host "... create new queue, set FullControl permissions for queuename"
$qb =[System.Messaging.MessageQueue]::Create(".\private$\queuename")

$qb.SetPermissions("queuename", 
  [System.Messaging.MessageQueueAccessRights]::FullControl,            
  [System.Messaging.AccessControlEntryType]::Set)

但是当我运行它时,我收到了这个错误:

Unable to find type [System.Messaging.MessageQueueAccessRights]. Make sure 
 that the assembly that contains this type is loaded.
At line:7 char:1
+ $qb.SetPermissions("hazeljob",
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo: InvalidOperation:(System.Messagin...eueAccessRi 
ghts:TypeName) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound

我认为可能是因为没有安装消息队列,但后来我安装了它仍然出现了这个错误。

为什么会这样?此代码与Windows Server 2008 R2不兼容吗?我将公司价值观输入最初的公司价值。

2 个答案:

答案 0 :(得分:1)

您的代码似乎有两个问题。

首先,您需要告诉PowerShell从全局程序集缓存中导入var data = { "sEcho": 1, "iTotalRecords": "7", "iTotalDisplayRecords": "7", "aaData": [ [null, "Tharanga Kumara", null, "Wanniassa, 2903", null], [null, "dsfadsf fdaf", null, "Ashford, 5035", null], [null, "fdafa dfdaf", null, "Wanniassa, 2903", null], [null, "Dilani Kumari", null, "dfdaf, 34234", null], [null, "Kamal Maduranga ", null, "Wanniassa, 2903", null], [null, "Sampath Gunathilaka", null, "Eastern Suburbs Mc, 2004", null], [null, "Kasun Sandaruwan", null, "Wanniassa, 2903", null] ] }; var cleanData = JSON.parse(JSON.stringify(data).replace(/null/g, "\"\"")); console.log(cleanData); 命名空间代码:

System.Messaging

接下来,在[System.Reflection.Assembly]::LoadWithPartialName("System.Messaging") | Out-Null 实例上使用SetPermission时,您不需要再次提供队列名称 - 它已经知道它是谁,可以这么说。

需要提供的内容是您要向其授予对邮件队列的访问权限的用户,安全组或计算机的用户名。

因此,如果您想在队列" MyQueue"上授予您自己的用户帐户FullControll访问权限,并且您的用户名是" david.wilson",那就变成:

MessageQueue

答案 1 :(得分:0)

希望这时已经或正在停用Server 2008实例,但是无论如何您都可以使用Powershell 5创建队列。

import os

os.system('bash')

https://docs.microsoft.com/en-us/powershell/module/msmq/new-msmqqueue?view=win10-ps