[英]Import users to local with powershell windows server 2008 r2
[英]Creating private queues in PowerShell on 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 不兼容? 我输入了我公司的价值而不是原来的价值。
您的代码似乎有两个问题。
首先,您需要告诉 PowerShell 从全局程序集缓存中导入System.Messaging
命名空间代码:
[System.Reflection.Assembly]::LoadWithPartialName("System.Messaging") | Out-Null
接下来,当在MessageQueue
实例上使用SetPermission
时,您不需要再次提供队列名称 - 它已经知道它是谁,可以这么说。
什么你需要供应给谁,你要授予访问权限到消息队列的用户,安全组或计算机的用户名。
因此,如果您想授予您自己的用户帐户 FullControll 对队列“MyQueue”的访问权限,并且您的用户名是“david.wilson”,则变为:
$Queue = [System.Messaging.MessageQueue]::Create(".\private$\MyQueue")
$Queue.SetPermissions("david.wilson",[System.Messaging.MessageQueueAccessRights]::FullControl, [System.Messaging.AccessControlEntryType]::Set)
希望 Server 2008 实例此时已经或正在停用,但无论如何您也可以使用 Powershell 5 创建队列。
function CreateQueue(
[string] $queueName,
[string] $queueType = 'Private'
) {
New-MsmqQueue -Name $queueName -QueueType $queueType
}
CreateQueue -queueName 'PrivateTestQueue'
https://docs.microsoft.com/en-us/powershell/module/msmq/new-msmqqueue?view=win10-ps
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.