Articles of PowerShell

两个PowerShell脚本之间的区别

我收到一个脚本,应该扫描4个DC的事件日志,search事件ID 4740(用户locking)。 这是第一个脚本。现在我想, “为什么扫描所有的DC,当我可以扫描angular色PDC模拟器的DC的日志? 所以我发现另一个脚本只能更快地完成相同的工作…现在我有4个问题: PDCe是否有自己的日志,或者是“一般”DC日志? 这两个脚本是否提及相同的来源? 为什么第一个花了大约一个小时,第二个花了大约15秒呢? 为什么第二个脚本只能输出8个小时? 第一个脚本: $DD = get-date -format d $DD $L = get-eventlog -logname security -computername dc1, dc2, dc3, dc4 -after $DD | where {$_.eventid -eq 4740 } | ft -autosize timegenerated.replacementstrings $L $L >> locked.accounts.txt 第二个脚本: $PDC = Get-ADDomainController -Discover -Service PrimaryDC Get-WinEvent -ComputerName $PDC -Logname Security -FilterXPath […]

通过Powershell发送维护消息给Citrix XenApp用户

我试图通过Powershell cmdlet send-xasessionmessage向XenApp用户发送消息。 环境包含约。 有100个活动会话的100台服务器。 剧本很慢。 当我在一台服务器上testing时,它工作正常。 但是当我input100个服务器时似乎只是挂起。 我是否需要使用工作..或其他什么..请build议,

如何从Active Directory查询(唯一)当前用户的信息?

如何从Active Directory查询当前用户的信息? 我知道我可以从Windows访问大量关于当前用户的信息,例如环境variables等。 我可以得到当前用户的用户名和域名,但是我需要在AD中查找相应的logging? 我特别想确定的是,我可以唯一地识别 AD中的当前用户,因为这个脚本必须处理大量的用户,并且任何潜在的歧义可能难以以编程方式解决。 做这个的最好方式是什么?

将参数作为parameter passing给-filterXPath get-wineventLogs

您好我做了PowerShell脚本,我正在采取三个论据(在参数块),并将它们作为parameter passing给-FilterXPath。 但是我无法得到结果。 $事件ID = 7036 $服务名称= PW $状态=停止 它给了我正确的结果,如果我把值而不是variables。 请帮忙。 这是非常紧急的。 param($eventID,$ServiceName,$Status) $eventID | add-content "path\hello.txt" $ServiceName | add-content "path\hello.txt" $Status | add-content "path\hello.txt" sleep 5 $ErrorTime=Get-WinEvent -LogName 'System' -FilterXPath 'Event[System[EventID=$(eventID)] and EventData[Data[@Name="param1"]="$(ServiceName)" and Data[@Name="param2"]="$(Status)" ]]' -MaxEvents 1 | select -expand timecreated $ErrorTime | add-content "path\hello.txt"

Powershell分割path格式

我在某些格式上遇到了一些问题。 我的代码查找文件夹结构中的新文件并返回这些项目,但我想修剪结果只显示path中的前3个文件夹。 反正有这样做使用拆分path? 例: 我在文件中返回的内容是:\\ Folder1 \ Folder2 \ Folder3 \ Folder4 \ File.txt 我想在拆分path后看到的是:\\ Folder1 \ Folder2 \ Folder3 码: $File = Get-ChildItem -File -Recurse $Path | Where { $_.LastWriteTime -ge (Get-Date).Addminutes(-5) } foreach ($item in $file){ $ItemDirectory = $Item.Directory $result = split-path $ItemDirectory -Parent $result 谢谢

如何从多个域中获取详细信息

我想通过PowerShell创buildAD报告,但无法从多个域获取详细信息, 下面是我的代码, # HTML Style $a = "<style>" $a = $a + "BODY{background-color:SkyBlue;font-family: calibri; font-size: 10pt;}" $a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: grey;border-collapse: collapse;}" $a = $a + "TH{border-width: 1px;padding: 5px;border-style: solid;border-color: black;}" $a = $a + "TD{border-width: 1px;padding: 5px;border-style: solid;border-color: black;}" $a = $a + "</style>" # Query Range $dt = (get-date).adddays(-3) # […]

PowerShell连接交换2013年PowerShell的随机工作?

我目前正在处理一个连接到我们的邮件服务器的脚本,并清除邮箱中的特定文件夹,除了连接到服务器之外,所有的工作都没有问题。 当我今天上午尝试时没有问题。 但是,如果我现在尝试我得到 The WinRM service cannot process the request because the request needs to be sent to a different machine. Use the redirect information to send the request to a new machine. Redirect location reported: h ttps://mail.mailserver.se/owa/PowerShell . To automatically connect to the redirected URI, verify the "MaximumConnectionRedirectionCount" property of the session preference variable […]

使用Powershell通过CSV导入ExtensionAttribute

我正在尝试使用CSV文件填充ExtensionAttribute7属性。 CSV文件有两列:samAccountName和ExtensionAttribute7 我导入Active Directory模块并尝试使用此脚本: Import-Csv C:\sam-eid.csv | ForEach-Object { Set-ADUser $_.samAccountName -Replace @{ExtensionAttribute7=$._ExtensionAttribute7}} 这是我得到的错误返回: $ ._ ExtensionAttribute7:术语“$ ._ ExtensionAttribute7”不被识别为cmdlet,函数,脚本文件或可操作程序的名称。 检查名称的拼写,或者如果包含path,请validationpath是否正确,然后重试。 在行:2 char:62 + … mAccountName -Replace @ {ExtensionAttribute7 = $ ._ ExtensionAttribute7}} + ~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo:ObjectNotFound :($ ._ ExtensionAttribute7:String)[],CommandNotFoundException + FullyQualifiedErrorId:CommandNotFoundException 有任何想法吗? 我试过了 – join而不是 – 取消无效。

使用vmware进行powerclimath – 数据存储属性划分algorithm

基本上,我得到所有0的百分比列中返回。 我需要帮助,我相信是语法或不正确的使用圆。 Get-Cluster "my_cluster" | Get-VMHost | Get-Datastore | Select Name,@{N="Percentagetest";E={[math]::Round(($_.ExtensionData.Summary.Capacity / $_.ExtensionData.Summary.Freespace)/1GB,3)}}

无法通过PowerShell将用户添加到本地组

尝试导入macauthentication的大量用户列表。 我可以创build用户,但无论我尝试什么,我都不能将它们添加到本地组。 我不断地得到“一个无效的目录path名被传递”给add函数。 这是实际的错误: Method invocation failed because [System.DirectoryServices.DirectoryEntry] does not contain a method named 'op_Addition'. At C:\Users\Administrator\Desktop\Import Script\Import1.ps1:12 char:2 + $objuser = [ADSI]"WinNT://RadiusSVR/" + $_.MAC + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (op_Addition:String) [], RuntimeException + FullyQualifiedErrorId : MethodNotFound Exception calling "Add" with "1" argument(s): "An invalid directory pathname was passed $Computername = $env:COMPUTERNAME $objgroup […]