标签: powershell

使用 powershell 获得与添加/删除程序完全相同的应用程序列表

有多种方法可以在系统上查找已安装的应用程序,但据我所知,没有一种方法返回与控制面板项添加删除程序完全相同的列表。我尝试的一些方法是:

  • WMI 通过 Win32_Product 和 Win32Reg_AddRemovePrograms
  • 注册表,x32 和 x64 分支

例如,我在 AR 中有 217 个条目和

gwmi  Win32_Product
Run Code Online (Sandbox Code Playgroud)

返回 261 项。

gp HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | ? {![string]::IsNullOrWhiteSpace($_.DisplayName) } | select DisplayName
Run Code Online (Sandbox Code Playgroud)

返回 119 个项目。

 (gwmi Win32Reg_AddRemovePrograms) + (gwmi Win32Reg_AddRemovePrograms64) | sort DisplayName -Unique 
Run Code Online (Sandbox Code Playgroud)

返回 107 个项目。

我试着用更复杂的过滤器,包括钉下来InstallLocation,InstallSource,InstallDate等没有成功。

powershell

6
推荐指数
1
解决办法
6510
查看次数

OU 使用 PowerShell 批量许可 Office 365 用户

我正在尝试做一些我认为修复起来不会太复杂的事情。我的最终目标:我在一个 AD OU 中的某些用户需要使用 Office 365 中的某个许可证,而另一个 OU 中的不同用户需要获得不同的许可证。

我想运行的命令是:

Get-ADUser -Filter * -SearchBase "ou=test,dc=our,dc=domain,dc=edu" | Set-MsolUserLicense -AddLicenses ourorg:STANDARDWOFFPACK_IW_STUDENT
Run Code Online (Sandbox Code Playgroud)

但这失败了:

Set-MsolUserLicense : The input object cannot be bound because it did not contain the information required to bind all mandatory parameters: ObjectId At line:1 char:111 + Get-ADUser -Filter * -SearchBase "ou=Test students,ou=Students,dc=campus,dc=org,dc=edu" | Set-MsolUserLicense <<<< -AddLicenses nwcu:STANDARDWOFFPACK_IW_STUDENT

单独地,这两个命令都有效。我可以选择 OU 中的所有用户,也可以手动使用 Set-MsolUserLicense 命令和 -UserPrincipalName 来许可单个用户。

这是因为 Get-ADUser 没有像 Set-MsolUserLicense 正在寻找的那样返回 ObjectID 吗?Get-ADUser 确实返回 ObjectGUID。如果我在这里走在正确的轨道上,有没有办法将这些映射到管道输入?

编辑:我知道这样做的流行方法涉及为此上传 CSV 文件,并且我知道我可以 CSV 导出这些用户,但我已经在 OU 中将它们整理得如此整洁,所以我很乐意这样做如果可能的话,现在导入/导出。 …

powershell active-directory microsoft-office-365 azure-active-directory

6
推荐指数
1
解决办法
2927
查看次数

我的服务帐户需要什么来解决 robocopy 中的“管理审核用户权限”错误?

我正在创建一个计划任务,该任务从 Windows Server 2012 R2 上的脚本调用 robocopy。无论它是手动运行还是从计划任务运行,它当前都会引发以下错误:

ERROR : You do not have the Manage Auditing user right.
*****  You need this to copy auditing information (/COPY:U or /COPYALL).
Run Code Online (Sandbox Code Playgroud)

该任务已设置为“无论用户是否登录都运行”和“以最高权限运行”。脚本如下:

Add-Content E:\ITS\CopyScripts\box1-backup-robocopy.log "script running"
#Input the variables for the robocopy script
$Source = "\\box1-prod\images\prod\"
$Destination = "E:\Box1\Backups\images"
$Retries = 1

#This is the Robocopy script
Robocopy.exe $Source $Destination /E /Z /COPYALL /XO /r:$Retries /purge /xd '$RECYCLE.BIN' 'System Volume Information' '._nfs' /log:E:\ITS\CopyScripts\box1-backup-robocopy.log /tee
Run Code Online (Sandbox Code Playgroud)

任何帮助解决这个问题将不胜感激。

powershell robocopy windows-server-2012-r2

6
推荐指数
1
解决办法
2万
查看次数

Get-AzureRmResourceGroup 不从当前订阅返回资源

如果我跑

Get-AzureSubscription -Current
Run Code Online (Sandbox Code Playgroud)

我得到:

SubscriptionId            : a*<guid>
SubscriptionName          : Development                         
Environment               : AzureCloud                          
DefaultAccount            : t*<guid>          
IsDefault                 : True                                
IsCurrent                 : True                                
TenantId                  : 4*<guid>
Run Code Online (Sandbox Code Playgroud)

然后我运行:

Get-AzureRmResourceGroup
Run Code Online (Sandbox Code Playgroud)

根据门户网站的说法,返回的两个资源都不在该订阅中,其中应该有很多资源:

ResourceGroupName : Default-SQL-NorthCentralUS
Location          : northcentralus
ProvisioningState : Succeeded
Tags              :
ResourceId        : /subscriptions/0*<guid>*e/resourceGroups/Default-SQL-NorthCentralUS

ResourceGroupName : Default-Web-NorthCentralUS
Location          : northcentralus
ProvisioningState : Succeeded
Tags              :
ResourceId        : /subscriptions/0*<guid>*e/resourceGroups/Default-Web-NorthCentralUS
Run Code Online (Sandbox Code Playgroud)

这些来自我的另一个订阅,但如您所见,不是当前订阅。

为什么没有Get-AzureRmResourceGroup获取当前订阅中的资源组,现在我要解决这个问题吗?

我的 Azure 模块是 0.9.11 版,AzureRM 是 1.0.1 版。我也无权访问Switch-AzureMode或Get-AzureResourceGroup

powershell azure

6
推荐指数
1
解决办法
4470
查看次数

Windows PowerShell - 如何查看命令历史日期/时间

我想列出在 Windows PowerShell 中输入的命令及其各自的时间戳。我怎样才能用Get-History命令做到这一点?

windows powershell windows-command-prompt command

6
推荐指数
1
解决办法
5755
查看次数

Powershell 远程处理突然停止工作

我在执行远程 powershell 脚本时遇到问题,该脚本应该更新应用程序的安装,以便在每天运行一次的任务管理器任务中进行自动化测试。

这个相当简单的脚本(详情如下)曾经成功运行了大约一年。突然它开始失败,因为无法执行远程PowerShell脚本。我不知道这是什么根本原因。本地 IT 确保他们没有更改任何内容。

(我应该注意,我可能可以用其他东西替换 powershell 脚本,但我不打算轻易放弃。除此之外,我想了解这里有什么问题)

这是一般设置:

未连接到域的 Windows Server 2008 R2 虚拟机,称为目标。u_target分配到目标上的管理员组的本地用户。

域中的 Windows Server 2008 R2 虚拟机(我们称为域 D),称为源。u_source分配给源上管理员组的域 D 用户。

Powershell 在两个 VM 上都有 2.0 版。

目标上的所有命令都u_target以管理员权限执行,源上的所有命令都u_source以管理员权限执行。在所有情况下,我都检查了 powershell 是否已以管理员身份启动。

大约一年前,我在两个 VM 上启用了 psremoting,如下所示:

在目标上,u_target 在 admin powershell 中执行 enable-psremoting -force, set-item wsman:\local\client\TrustedHosts -value 'source' 然后机器重新启动。

两个命令都执行没有任何错误。后来,当我遇到麻烦时,我用 * 替换了 'source' 以确保问题不是由于打字错误造成的。

在源代码中,u_source在 admin powershell 中执行 enable-psremoting -force。这台机器也重新启动了。

后来,当事情失败时,目标也被添加到了 TrustedHosts 中。

应该执行的脚本原则上如下所示:

$server = 'target' …
Run Code Online (Sandbox Code Playgroud)

remote-access powershell remoting

6
推荐指数
1
解决办法
2301
查看次数

通过 GPO 安装 Powershell 模块

我发现一个模块真的很有趣,并想在整个 AD 域中使用它。有什么办法可以使这个过程自动化?在普通的 Powershell 中,我必须使用管理员权限简单地调用此命令:

Install-Module -Name $moduleName
Run Code Online (Sandbox Code Playgroud)

如果它是不受信任的存储库,那么我必须更改它:

Set-PSRepository -name $repoName -InstallationPolicy trusted
Run Code Online (Sandbox Code Playgroud)

我正在寻找更优雅的方式,而不是在计算机启动时运行这些命令,作为简单的 PS 脚本。

理想的解决方案如下所示:

  1. 有些东西会检查,如果计算机上安装了模块。
  2. 如果没有,则安装模块,并且计算机从现在开始被识别为安装了模块的机器。
  3. 如果它确实安装了模块,则不采取任何操作。

或者甚至更好:

  1. 有某种容器,其中包含没有安装模块的计算机。
  2. 模块安装在此容器中的每台计算机上,然后移出容器。

第二个可以在简单的域容器上工作,在那里我们得到了带有 GPO 的子容器,它使用上面的命令运行 PS 脚本。我们可以使用 PS Active Directory cmdlet 通过这种结构移动计算机。我看到下一个问题,自动从容器移动到另一个容器,在更大范围内和更长时间内是否安全?

powershell active-directory group-policy

6
推荐指数
1
解决办法
3347
查看次数

不能将 UPN 凭据与 New-MoveRequest 一起使用?

我们采用的是混合设置(本地 Exchange 2013),并且 MRSproxy 已启用并正常工作。我们希望在用户离开公司时将其邮箱存档。因此,我们希望将这些邮箱从 O​​ffice 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)

powershell microsoft-office-365 exchange-2013

6
推荐指数
1
解决办法
2752
查看次数

添加的功能越多,添加到 Windows Server 的速度就越慢

我正在解决我们在所有 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)

powershell windows-server-2016

6
推荐指数
1
解决办法
660
查看次数

如何查找磁盘是否进行精简配置?

我已将 IScsi 卷映射到我的 Windows 2016 服务器中。我已经用它们创建了磁盘。现在我需要确定磁盘是否是精简配置的。

我正在尝试使用以下 cmdlet

获取磁盘和获取物理磁盘

但没有运气。如何使用powershell查找磁盘是否进行精简配置?

windows powershell iscsi thin-provisioning

6
推荐指数
1
解决办法
763
查看次数