Articles of PowerShell

使用PowerShell添加AD组

我试图写一个脚本来添加一个组到一个OU,我已经剥离了脚本,并使用命令行来查找错误,它看起来像-path是不正确的,我如何使用powershell创build一个组在特定的OU中不使用-path。 命令 New-ADGroup -name _AB_Read -GroupCategory Security -GroupScope Global -Path OU = TEST,OU = NEW_Groups,DC = Corp1,DC = net 错误 New-ADGroup:无法将“System.Object []”转换为参数“Path”所需的types“System.String”。 指定的方法不受支持。 在线:1个字符:77 新build-ADGroup -name _PL_Read -GroupCategory安全-GroupScope Global -Path OU = V … ~~~~ CategoryInfo:InvalidArgument:(:) [New-ADGroup],ParameterBindingException FullyQualifiedErrorId:CannotConvertArgument,Microsoft.ActiveDirectory.Management.Commands.NewADGroup

如何使用powershell v2.0或CMD / VBS检查是否在AD中禁用了特定的用户帐户列表

1)我有一个tAM列表与sAMAaccountNames 2)我需要查询每个帐户名称,并validation它是否被禁用 3)如果账户被禁用,从AD中删除它 如果没有其他办法,我只是手动删除它们,但首先我需要检查我的列表中的所有帐户,看看他们是否被禁用。 我在这个服务器上安装了powershell v2.0,DC是windows server 2003.pipe理服务器是windows server 2008。 我没有Active Directory模块,也无法安装它。 我怎样才能做到这一点与CMD / VBScript或PowerShell的v2.0? 我试图跑 dsquery -Filter "(userAccountControl:1.2.840.113556.1.4.803:=2)" 但我得到以下错误dsquery failed:The parameter is incorrect.:Incorrect object type specified. type dsquery /? for help. dsquery failed:The parameter is incorrect.:Incorrect object type specified. type dsquery /? for help.

脚本启用即时文件初始化secedit

我希望能够通过T-SQL或Powershell在新的或现有的Windows Server服务器上打开IFI http://bit.ly/1dK32Dc 。 不想通过“本地安全>本地策略>用户权限分配>执行卷维护任务>添加用户”路由 – 需要通过脚本部署新机器,无需手动交互。 假定SQL Server服务帐户不更改。 对于新安装,当我select帐户时,我可以运行下面的Powershell脚本,并解决了这个问题: $sqlaccount = "domain\account" # https://technet.microsoft.com/en-gb/library/bb490997.aspx secedit /export /cfg C:\secexport.txt /areas USER_RIGHTS $line = Get-Content C:\secexport.txt | Select-String 'SeManageVolumePrivilege' (Get-Content C:\secexport.txt).Replace($line,"$line,$sqlaccount") | Out-File C:\secimport.txt secedit /configure /db secedit.sdb /cfg C:\secimport.txt /overwrite /areas USER_RIGHTS 但是,对于现有的SQL安装,无法想象查询已configuration的SQL Server服务帐户的方法 – 并将其提供给此脚本。 考虑到WS 2012 R2的解决scheme,但是在WS 2003 R2上也可以使用的解决scheme是最好的(如果我没有弄错的话,支持Powershell 2)。

如何将远程PowerShell会话build立到Azure虚拟机的公共IP地址?

我尝试通过其公共IP地址获取部署在Azure上的Windows Server 2016的远程PowerShell会话(最初我试图configuration服务器pipe理工​​具网关,但是即使在两个完全相同的新部署的服务器之间,我也无法使其工作)。 我有两台服务器(目标10.0.0.4和源10.0.0.5 )连接到同一个子网,我可以从源连接到本地networking上的目标( 10.0.0.0 ): PS C:\> Set-Item WSMan:\localhost\Client\TrustedHosts -Value "10.0.0.4" -Concatenate -Force PS C:\> Enter-PSSession -ComputerName 10.0.0.4 -Credential (Get-Credential) cmdlet Get-Credential at command pipeline position 1 Supply values for the following parameters: Credential [10.0.0.4]: PS C:\Users\techraf\Documents> exit 但是,如果我尝试使用目标的公共IP地址,连接就会被拒绝: PS C:\> Set-Item WSMan:\localhost\Client\TrustedHosts -Value "13.85.78.151" -Concatenate -Force PS C:\> Enter-PSSession -ComputerName 13.85.78.151 -Credential […]

使用Azure VM中的PowerShell检索用于存储池的磁盘的VHD

我想知道哪些VHD用于特定的存储池。 使用跨平台CLI,我可以获得LUN和blob名称: $ azure vm disk list testvm info: Executing command vm disk list + Fetching disk images + Getting virtual machines + Getting VM disks data: Lun Size(GB) Blob-Name OS data: — ——– ———————————————— ——- data: 128 testvm-testvm-os-1457591813350.vhd Windows data: 0 1023 testvm-disk1.vhd data: 1 1023 testvm-disk2.vhd data: 2 1023 testvm-disk3.vhd data: 3 1023 […]

将列表input传递给Get-ADComputer

所以我写了一个脚本,从AD获取关于用户及其相关计算机的一些信息。 我已经在线阅读了关于Get-ADComputer cmdlet以及一些可能的错误的人们面临的一些问题。 起初我以为那是我碰到的,但现在我不太确定。 我的问题是,我的代码工作正常,但如果我添加一个不相关的代码片段从variables获取一些信息,它打破了别的东西。 看一看。 整个代码: http : //paste.ofcode.org/Hgbiukp2XYqKnv2sdUGBKb 有问题的代码位: ## Prompt host for input $username = Read-Host -Prompt "Enter the Username" ## Get list of computers $ComputerList = Get-ADComputer -Filter {ManagedBy -eq $username} -Properties ManagedBy | Select-Object -ExpandProperty Name ## Compute and format results Foreach ($Computer in $ComputerList) { $OnlineStatus = Test-Connection -ComputerName […]

通过PID powershell杀死(closures)可靠性监视器窗口

我想创build一个Windows可靠性监视器的进程,并在我截图后杀死它。 我无法获取该进程,并在截取屏幕之前自动closures它,因为没有标识该窗口的进程ID。 有什么办法通过PowerShellclosures可靠性监视器? $psi = New-object System.Diagnostics.ProcessStartInfo $psi.CreateNoWindow = $false $psi.UseShellExecute = $true $psi.RedirectStandardOutput = $false $psi.RedirectStandardError = $false $psi.FileName = "Perfmon" $psi.Arguments ="/rel" $process = New-Object System.Diagnostics.Process $process.StartInfo = $psi [void]$process.Start() #$output = $process.StandardOutput.ReadToEnd() $process.id Start-Sleep 5

使用Powershell设置IIS网站经典ASP会话超时

如何使用PowerShell在IIS 8.5中设置经典ASP会话超时? 我看了一下使用Set-WebConfigurationProperty但不能解决如何正确使用它。

目录服务事件日志

情况:我需要每小时检查一次多个服务器的目录服务事件日志。 为了做到这一点,而不击碎数据中心,并不受networking速度的约束,我正在复制evtx文件到不同的机器。 缺点是,我正在处理的计算机上没有ADangular色,也没有安装它,这意味着logparser.exe和PowerShell Get-WinEvent等工具无法读取日志中的消息信息。 我正在寻找的是一种方式来从程序上读取事件日志中的消息或能够加载DLL /程序集,以方便阅读。 PowerShell强烈首选,因为我不是一个.NET开发人员。 提前感谢你的帮助。

开始BITSTransfer与networking共享作为目的地

我正在使用Start-BITSTransfer从互联网下载文件并将其放置在networking位置。 该位置类似于\\computername\c$\folder ,该cmdlet表示无法find并且不存在。 为了使Test-Path成功通过,必须将文件系统提供程序添加到以下位置: filesystem::\\computername\c$\folder 。 蹭的是, Start-BITSTransfer不像声明文件系统提供程序那样的目的地,并且“path不是合法forms”的错误。 由于无法使用Invoke-Command并在目标服务器的远程shell中运行代码,问题进一步复杂化。 Start-BITSTransfer阻止这种用法。 在networking位置使用Start-BITSTransfer的解决scheme是什么?