我正在尝试使用参数创建一个可靠的 PowerShell 函数。现在的问题是我没有让 ParameterSetNames 工作。
我想得到的是
我尝试了很多不同的设置,但一直失败这是我最后一次尝试
CmdletBinding(DefaultParameterSetName="IpAddress")]
[CmdletBinding()]
Param
(
# computername: Name of the host you want to connect to.
[Parameter(Mandatory=$true,ParameterSetName="ComputerName", Position=0)]
[Parameter(Mandatory=$false,ParameterSetName="IpAddress")]
[Parameter(Mandatory=$true,ParameterSetName="ComputerNameCredentials", Position=0)]
[Parameter(Mandatory=$false,ParameterSetName="IpAddressCredentials")]
[Parameter(Mandatory=$false,ParameterSetName="IpAddressUser")]
[Parameter(Mandatory=$true,ParameterSetName="ComputerNameUser", Position=0)]
[String]$computername,
# ipAddress: Ip Address of the host you want to connect to.
[Parameter(Mandatory=$false,ParameterSetName="ComputerName")]
[Parameter(Mandatory=$true,ParameterSetName="IpAddress", Position=0)]
[Parameter(Mandatory=$false,ParameterSetName="ComputerNameCredentials")]
[Parameter(Mandatory=$true,ParameterSetName="IpAddressCredentials", Position=0)]
[Parameter(Mandatory=$true,ParameterSetName="IpAddressUser", Position=0)]
[Parameter(Mandatory=$false,ParameterSetName="ComputerNameUser")]
[switch]
[String]$ipAddress,
# credentials: PowerShell credentials use to connect to the host.
[Parameter(Mandatory=$false,ParameterSetName="ComputerName")]
[Parameter(Mandatory=$false,ParameterSetName="IpAddress")]
[Parameter(Mandatory=$true,ParameterSetName="ComputerNameCredentials")]
[Parameter(Mandatory=$true,ParameterSetName="IpAddressCredentials")]
[Parameter(Mandatory=$false,ParameterSetName="IpAddressUser")] …Run Code Online (Sandbox Code Playgroud) 为什么不Get-Computers -OperatingSystem "Windows VistaT Business"返回任何东西?它适用于所有其他操作系统类型。
Function Get-Computers
{
Param($OperatingSystem)
Get-AdComputer -Filter 'OperatingSystem -eq ${OperatingSystem}' -SearchBase "OU=Departement,DC=contoso,DC=com"
}
#Get-Computers -OperatingSystem "Windows Server 2012 R2 Standard"
#Get-Computers -OperatingSystem "Windows Server 2008 R2 Standard"
#Get-Computers -OperatingSystem "Windows 7 Professional"
Get-Computers -OperatingSystem "Windows VistaT Business"
Run Code Online (Sandbox Code Playgroud)
我肯定有 Vista 客户端,要查找的字符串是Windows VistaT Business.
PS C:\> (get-adcomputer ClientA -Properties *).OperatingSystem
Windows 7 Professional
PS C:\> (get-adcomputer ClientB -Properties *).OperatingSystem
Windows VistaT Business
Run Code Online (Sandbox Code Playgroud) 有没有办法通过批处理或powershell脚本来做到这一点?我正在寻找一种方法来设置几个新服务器。
我在这个主题上发现的唯一一件事让我相信你不能:来自:http : //technet.microsoft.com/en-us/library/cc785060.aspx
只能使用计算机管理、服务和应用程序、消息队列属性中的存储选项卡修改消息存储位置。
编辑 - 我也找到了这篇文章。它列出了一些注册表值,但再次建议不要使用它 http://blogs.msdn.com/b/johnbreakwell/archive/2009/02/09/changed-the-msmq-storage-location.aspx
最近,我的组织成为垃圾邮件攻击的受害者。可悲的是,一些用户提供了他们的电子邮件和密码。攻击者设置了一长串要发送的电子邮件(来自受害者帐户)。
我们必须手动删除所有消息(从队列查看器中)。这是非常痛苦的(超过 10 万封电子邮件......)。
是否可以使用 PowerShell 清除特定用户的电子邮件队列?(使用 Active Directory 模块)
找到了这个旧帖子,但它看起来已经过时并且删除了所有队列...
我的目标是通过 PowerShell 将 Windows 中的网络驱动器映射到 WebDAV 服务器。
我有一个脚本可以自动创建一个安装了 IIS 并配置了 WebDAV 的 Azure VM。我可以通过 Windows 资源管理器成功地将网络驱动器手动映射到 WebDAV 服务器(使用使用不同凭据的选项)。这确认 WebDAV 服务器配置正确。我也可以读写文件。
通过 PowerShell,我尝试使用命令 New-PSDrive 并得到如您所见的错误。
New-PSDrive –Name $networkDrive –PSProvider FileSystem –Root "http://$serviceName.cloudapp.net/" –Persist
New-PSDrive : When you use the Persist parameter, the root must be a file system location on a remote computer.
At line:1 char:1
+ New-PSDrive –Name $networkDrive –PSProvider FileSystem –Root "http:// ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (Z:PSDriveInfo) [New-PSDrive], NotSupportedException
+ FullyQualifiedErrorId : DriveRootNotNetworkPath,Microsoft.PowerShell.Commands.NewPSDriveCommand
Run Code Online (Sandbox Code Playgroud)
或不带参数 -Persist
New-PSDrive …Run Code Online (Sandbox Code Playgroud) 我们采用的是混合设置(本地 Exchange 2013),并且 MRSproxy 已启用并正常工作。我们希望在用户离开公司时将其邮箱存档。因此,我们希望将这些邮箱从 Office 365 迁移回我们的内部部署服务器。我一直在尝试创建一个离开脚本,并且New-MoveRequestcmdlet 不断给出以下错误:
The Mailbox Replication Service was unable to connect to the remote server using the credentials provided. Please check the credentials and try again. The call to 'https://webmail.blah.com/EWS/mrsproxy.svc' failed.
Error details: The HTTP request is unauthorized with client authentication scheme 'Negotiate'. The authentication header received from the server was 'Negotiate,NTLM'. --> The remote server returned an error:
(401) Unauthorized.. --> The HTTP request is unauthorized with client authentication scheme 'Negotiate'. …Run Code Online (Sandbox Code Playgroud) 我正在解决我们在所有 Windows Server 2016 服务器中看到的问题。我们向操作系统添加的功能越多,添加的功能就越慢。
例如,Add-WindowsFeature -Name NET-Framework-Core当我没有添加任何其他功能时执行,它以正常速度运行。
但是,在我添加了几十个功能(通常是 Web 服务器)之后,例如执行Add-WindowsFeature -Name Web-CGI需要超过 10 分钟。可以想象,这使得启动新服务器的速度非常慢,因为每台机器都添加了大约 60 个功能。
执行命令-LogFile会给出一个无用的日志,内容如下:
5756: 2017-12-19 19:40:57.545 [ServerManagerPS] Complete initializing log file.
5756: 2017-12-19 19:40:58.199 [ServerManagerPS] 45d625fe-30ef-4636-a79f-5ed8b9546d68 Enumerate server component ended with Success.
5756: 2017-12-19 19:41:03.268 [ServerManagerPS] 45d625fe-30ef-4636-a79f-5ed8b9546d68 Alter server component started. Component names: Web-CGI
5756: 2017-12-19 19:41:03.286 [ServerManagerPS] 45d625fe-30ef-4636-a79f-5ed8b9546d68 Alter server component ended with InProgress. The progress is 20
5756: 2017-12-19 19:41:04.295 [ServerManagerPS] 45d625fe-30ef-4636-a79f-5ed8b9546d68 Alter server component …Run Code Online (Sandbox Code Playgroud) 我已将 IScsi 卷映射到我的 Windows 2016 服务器中。我已经用它们创建了磁盘。现在我需要确定磁盘是否是精简配置的。
我正在尝试使用以下 cmdlet
获取磁盘和获取物理磁盘
但没有运气。如何使用powershell查找磁盘是否进行精简配置?
欢迎,我有关于通过 Powershell 管理磁盘的问题。是否有可能(如在 DISKPART 中) - 将磁盘类型更改为动态, - 创建镜像磁盘, - 创建 raid-5 卷, - 扩展卷但是是否可以使用 Powershell 做到这一点?我的意思是我需要使用 Powershell 而不是 DISKPART 来做这些事情,但找不到任何解决方案
我希望能够通过脚本确定给定的 Windows 工作站是加入 AAD、混合 AD 还是加入本地 AD。
我想从我正在使用的 RMM 运行此脚本,这样我就可以将这些结果存储在 RMM 中,并能够轻松地将计算机分为这三个类别(加上一个用于未加入任何类型域的工作站的类别)。
我使用的 RMM 以 NT AUTHORITY\SYSTEM 身份运行 powershell 脚本。
获取此信息的通常推荐方法是运行命令
dsregcmd /status
Run Code Online (Sandbox Code Playgroud)
然而,根据微软的文档
dsregcmd /status 实用程序必须作为域用户帐户运行。
我在自己的测试中验证了在 Powershell 中运行 dsregcmd /status 作为 NT AUTHORITY\SYSTEM 返回错误
dsregcmd : The term 'dsregcmd' is not recognized as the name of a cmdlet, function, script file, or operable program.
Run Code Online (Sandbox Code Playgroud)
在 cmd 中运行该命令会返回类似的错误。
当我尝试指定 dsregcmd.exe 的完整路径时,错误是相同的。
有没有办法让这个命令在以 SYSTEM 身份运行时起作用?或者,是否有另一种方法可以确定工作站在以 SYSTEM 身份运行时是否已加入 AAD?
powershell ×10
windows ×3
batch-file ×1
entra-id ×1
exchange ×1
iscsi ×1
msmq ×1
storage ×1
webdav ×1