如何检查 PowerShell v2.0 是否安装在服务器列表中?服务器列表是 Windows Server 2003 和 Windows Server 2008 的组合。vbscript 或 PS 脚本会很棒。
我知道 PowerShell 默认安装在 Windows Server 2008 中,但我只是想确保有人没有弄乱服务器。
我有一台带有所有当前 Windows 更新的 Windows 2008 R2 SP1 服务器。我正在尝试运行 PowerShell,但出现以下错误:
内部 Windows PowerShell 错误。加载托管 Windows PowerShell 失败,错误为 80070002
然后它立即返回到 cmd 行。
我已经运行了sfc /scannow,它已经恢复干净了。
我试过跑步 powershell -noprofile
所以我使用的是 DSC 推送模式
我每天有大约 200 次部署到多个环境 (DEV/INT/QA/PROD)
每次部署时,我都想确保每个服务器都配置正确
所以我自动运行 DSC 作为我部署的一部分,完全没有用户交互
所以我想知道是否有办法知道在运行 DSC 配置后是否需要重新启动/重启
基本上在运行这条线之后
Start-DscConfiguration -Wait -Force -Path .\SomePath
Run Code Online (Sandbox Code Playgroud)
我如何配置包的示例
Package MVC3
{
Name = "Microsoft ASP.NET MVC 3"
Ensure = "Present"
Path = "$Env:SystemDrive\AspNetMVC3ToolsUpdateSetup.exe"
ProductId = "DCDEC776-BADD-48B9-8F9A-DFF513C3D7FA"
Arguments = "/q"
DependsOn = "[WindowsFeature]IIS"
Credential = $Credential
}
Package MVC4
{
Name = "Microsoft ASP.NET MVC 4 Runtime"
Ensure = "Present"
Path = "$Env:SystemDrive\AspNetMVC4Setup.exe"
ProductId = "942CC691-5B98-42A3-8BC5-A246BA69D983"
Arguments = "/q"
DependsOn = "[Package]MVC3"
Credential = $Credential
}
Run Code Online (Sandbox Code Playgroud) 我有一个 Powershell 脚本,它使用了在 powershell 3.0 中工作的 Invoke-RestMethod。但是,我升级到 powershell 4.0 以修复 powershell 3 中的错误。当我这样做时,我的脚本似乎已停止工作。
$username = "Administrator"
$password = "PASSWORD"
$uri = "https://10.0.0.18/vmrest/users"
$dictionary = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f$username,$password)))
$dictionary.Add("Authorization",$base64AuthInfo)
Invoke-RestMethod -Uri $uri -Method GET -Headers $dictionary -Verbose
当我打开详细开关时,它给了我这个响应
VERBOSE: GET https://192.168.1.18/vmrest/users with 0-byte payload
VERBOSE: received -1-byte response of content type
我也尝试指定请求的内容类型,但没有骰子
$dictionary.Add("Accept","application/json")
$dictionary.Add("Connection", "keep_alive")
我被要求生成一个包含大约 50 个用户的列表所属的安全组(特别是不是通讯组)的列表。
我有一个用户列表,users.txt其中包含一个新行的每个用户名。我想生成一个membership.txt包含用户名和用户所属的安全组列表,用逗号分隔。
到目前为止我编写的Powershell脚本如下:
$users = Get-Content C:\users.txt
ForEach ($User in $users) {
$getmembership = Get-ADUser $User -Properties MemberOf | Select -ExpandProperty memberof
$User + ',' + $getmembership | Out-File -Append c:\membership.txt
}
Run Code Online (Sandbox Code Playgroud)
这几乎有效,但有两个问题:
OU=Security Groups,OU=City,DC=domain,DC=com CN=Senior Leaders,但我真正想要的唯一信息是Senior Leaders. 我怎样才能删除所有额外的信息?我正在尝试使用参数创建一个可靠的 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)