标签: powershell

脚本 - 如何断开远程桌面会话?

我正在寻找一种方法来关闭计算机(本地计算机)上的所有活动远程桌面会话。Windows 包含几个命令(rwinsta、qwinsta 等)来查看活动会话,但我不知道如何轻松使用这些信息(除非我解析字符串...)来关闭所有会话。

Powershell(或 C#、Batch)中有没有办法关闭本地计算机上的所有远程桌面会话?

谢谢,马丁

windows powershell windows-xp remote-desktop

9
推荐指数
2
解决办法
5万
查看次数

powershell 如何删除损坏的符号链接

PS C:\> cmd /c mklink /d testlink non-existent-dir
symbolic link created for testlink <<===>> non-existent-dir
PS C:\> rm .\testlink
Remove-Item : C:\testlink is a NTFS junction point. Use the Force parameter to delete or modify.
At line:1 char:3
+ rm <<<<  .\testlink
    + CategoryInfo          : WriteError: (C:\testlink:DirectoryInfo) [Remove-Item], IOException
    + FullyQualifiedErrorId : DirectoryNotEmpty,Microsoft.PowerShell.Commands.RemoveItemCommand

PS C:\> rm -force .\testlink
Remove-Item : Could not find a part of the path 'C:\testlink'.
At line:1 char:3
+ rm <<<<  -force .\testlink
    + CategoryInfo          : …
Run Code Online (Sandbox Code Playgroud)

powershell

9
推荐指数
1
解决办法
7033
查看次数

Powershell 使用 CNAME 远程处理到服务器,而不是计算机名称

我试图让 powershell 远程处理使用它的 CNAME 而不是计算机名称与服务器一起工作。本地和远程机器都在同一个网络和域中。

我启用了 powershell 远程处理,并且它与计算机名称一起工作正常。我已将 TrustedHosts 设置为 CNAME 并为 CNAME 添加了 SPN,但是当我发出时,Enter-PSSession CNAME我得到以下信息:

Enter-PSSession : Connecting to remote server CNAME failed with the following
error message : WinRM cannot process the request. The following error
occurred while using Kerberos authentication: Cannot find the computer CNAME.
Verify that the computer exists on the network and that the name
provided is spelled correctly. For more information, see the
about_Remote_Troubleshooting Help topic.
Run Code Online (Sandbox Code Playgroud)

执行setspn -l COMPUTERNAME给了我这个:

Registered …
Run Code Online (Sandbox Code Playgroud)

powershell windows-server-2008

9
推荐指数
1
解决办法
7020
查看次数

未激活通过 appcmd 更改 IIS 上的物理路径

我们在 IIS 7.5 上遇到了一个问题,我们有一个简单的部署系统,它包含以下内容:

创建一个新的 webroot 的 zip 文件,包含三个文件夹:

Api
Site
Manager
Run Code Online (Sandbox Code Playgroud)

它被解压到一个新文件夹中(假设我们称之为“SITE_REV1”),并包含一个调用以下内容的脚本(每个 webroot 一个):

C:\Windows\system32\inetsrv\appcmd set vdir "www.site.com/" -physicalPath:"SITE_REV1\Site"

这通常工作,在 9/10 倍。在某些情况下,webroot 似乎已正确更新(如果我检查 IIS 管理器中的基本设置,路径看起来是正确的),但有问题的运行站点实际上指向旧位置。我们设法“修复它”的唯一方法是运行 IIS 重置。仅回收有问题的应用程序池是不够的。

有时似乎甚至有必要重新启动,但我不能 100% 确定这是准确的(并非总是我自己在解决问题)。

我使用 Powershell 和 Web-Administration 模块重写了脚本,希望 appcmd 中存在故障,但发生了同样的问题。

Set-ItemProperty "IIS:\Sites\www.site.com" -Name physicalPath -Value "SITE_REV1\Site"

有没有人经历过这样的事情?有没有人知道发生了什么,我可以尝试做些什么来防止这个问题?执行 IIS 重置对我们来说并不是一个好的选择,因为每次我们尝试在单个站点上部署更改时,这都会影响服务器上的所有站点。

编辑:我们已经确定在 IIS 管理器中启动/停止站点(而不是应用程序池)可以解决错误的物理路径,但是如果我使用 appcmd 停止站点,更改物理路径,然后启动它,我仍然遭受同样的问题。我在一片空白...

scripting powershell deployment iis-7.5 appcmd

9
推荐指数
1
解决办法
6060
查看次数

使用 PowerShell 检测 AD 站点选项

如何使用 PowerShell 查找 AD 站点选项,例如+IS_INTER_SITE_AUTO_TOPOLOGY_DISABLED在 PowerShell 中?我一直在玩以下命令,但无法让它吐出任何有用的东西。

Get-ADObject -Filter 'objectClass -eq "site"' -Searchbase (Get-ADRootDSE).ConfigurationNamingContext` -Properties options
Run Code Online (Sandbox Code Playgroud)

powershell active-directory

9
推荐指数
1
解决办法
4265
查看次数

使用 Powershell 编辑/设置 Mime 类型?

所以我想知道是否有一种特定的方法可以使用 powershell 在 IIS 7.5 中更改/编辑 mime 类型?

到目前为止,我所遇到的解决方案,以添加MIME类型,如: http://sclarson.blogspot.co.at/2011/08/adding-mime-type-to-iis-vis-powershell.html HTTP://论坛。 iis.net/t/1192371.aspx 和其他一些有书籍被引用但这些书籍不包含任何信息,我查了一下。

似乎使用了Add-WebConfigurationPropertyis used,但是当我将此方法用于现有的 mimetype 时,我将收到与重复项条目相关的错误(因为它已经在那里),因此此方法不在窗口中。

我试图改用 ,Set-WebConfigurationProperty但这导致它删除了所有现有的 mimetype 条目并只留下其中一个。

那么有没有人有建议或者可能知道这样做的正确方法?我还考虑过先删除条目然后添加它,唯一的问题是您需要知道 mimetype fileExtension 和 mimeTypes(即文本/XML 等)。所以我假设我需要首先使用该getwebconfigproperty方法获取两个属性,然后通过将其中的值解析到函数中来删除它delete-webpropconfig,然后添加它......但是仅仅通过三个步骤来设置一个 mimetype 似乎过度了..

据我所知,appcmd.exe set config "values and params here" 方法几乎可以直接执行.. 然而,这个问题是不幸的是我们不能使用它。是的,我知道我可以让 powershell 执行 appcmd 命令,但不幸的是这不是一个可行的选择。我曾尝试谷歌搜索和阅读书籍以寻求解决方案,但到目前为止还没有想出答案

1) 该set-webconfigurationproperty方法删除所有其他 mimetype 条目

2)add-webconfigurationproperty不允许我执行它并抛出“错误重复”消息

3) 在 1 行中使用 powershell 执行此操作的可行解决方案。

iis powershell

9
推荐指数
3
解决办法
1万
查看次数

如何查找本地用户帐户的创建日期?

我想获取本地用户帐户的创建日期(如果重要,请使用 Win 7)。我查看了以下 WMI 对象(当然还有谷歌):

Win32_UserAccount Win32_NetworkLoginProfile

返回的对象NetworkLoginProfile具有上次登录时间,但没有创建日期。检查Date Created他们的配置文件文件夹的属性只会给出该文件夹的创建日期,不一定是帐户本身。

windows powershell wmi user-accounts

9
推荐指数
1
解决办法
5万
查看次数

复制项目文件系统提供程序错误

Copy-item cmdlet 没有按预期工作,我不明白为什么。这是我的代码:

$Source = "C:\folder1"
$Destination = "\\172.22.0.115\c$\folder2\"
$Password  = ConvertTo-SecureString -AsPlainText -Force -String "MyPassword"
$User = "Domain\Administrator"
$credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user,$password

Copy-Item $Source -Destination $Destination -Credential $credentials 
Run Code Online (Sandbox Code Playgroud)

这是我得到的错误:

The FileSystem provider supports credentials only on the New-PSDrive cmdlet. Perform 
the operation again without specifying credentials.
At C:\Sans titre2.ps1:7 char:1
+ Copy-Item $Source -Destination $Destination -Credential $credentials
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotImplemented: (:) [], PSNotSupportedException
    + FullyQualifiedErrorId : NotSupported
Run Code Online (Sandbox Code Playgroud)

我也试过这个:

Start-BitsTransfer -Source $source -Destination $Destination …
Run Code Online (Sandbox Code Playgroud)

scripting windows powershell windows-server-2012 windows-server-2012-r2

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

ESXcli 命令超时 30 分钟

我正在编写一个 powercli 脚本来循环遍历我们环境中的每个数据存储并回收精简配置的 LUN 上的空间。环境中的所有 LUN 都是 Dell Equal Logic。

vCenter 版本: 5.5.0_1750787

ESXi 版本: Dell 5.5-1331820(A01)

我遇到的问题是,在脚本中执行 unmap 命令后正好 30 分钟,我收到以下错误:

从 PowerCLI:

Message:  An error occurred while communicating with the remote host:
InnerText:
At \\SOMEIP\Share\folder\vmware_unmap_datastore.ps1:96 char:9
+        $RETVAL = $ESXCLI.storage.vmfs.unmap(200, $ds.Name, $null)
+        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CatagoryInfo          : OperationsStopped: (:) [], HostCommunication
    + FullyQualifiedErrorId : VMware.VimAutomation.ViCore.Types.V1.ErrorHandling.HostCommunication
Run Code Online (Sandbox Code Playgroud)

来自:ESXi 主机 vpxa.log:

==> vpxa.log <==
2014-06-30T14:39:51.907Z [7265EB70 error 'vpxavpxaVmomi' opID=60e7b2a5-11]
[VpxaClientAdapter::InvokeCommon] Got exception while invoking executeSoap
on vmodl.reflect.ManagedMethodExecuter:ha-managed-method-executer:
'Operation timed out', backtrace: …
Run Code Online (Sandbox Code Playgroud)

powershell timeout vmware-esxi powercli dell-equallogic

9
推荐指数
1
解决办法
8089
查看次数

Powershell 远程删除 PKI 证书

我最近重建了我的 PKI,我想删除颁发给我网络中所有客户端计算机的证书。听起来像是 Powershell 的工作!所以我写了这个脚本由 GPO 分发,从 SysVol 运行,并在启动时在客户端机器上触发:

set-location cert:\LocalMachine\My
$certname = $env:COMPUTERNAME + ".domain.com"
get-item * | %{
if($_.issuer -like "CN=IssuingCA*" -and $_.DnsNameList.unicode -like $certname) { remove-item .\$_.Thumbprint -Force }
}
Run Code Online (Sandbox Code Playgroud)

从提升的命令提示符:

  • 当 Ran 时,脚本不提供任何输出(只是一个新的终端行)。它不会返回任何错误并且不会删除证书。
  • 当参数-WhatIf添加到Remove-Item脚本中的命令时,同样没有错误并且证书不会被删除。
  • 当 Remove-Item .\CERTIFICATE-THUMBPRINT -Force 运行时,证书被删除。

这是权限问题吗?有没有更聪明/更简单的方法来做到这一点?

谢谢!

powershell pki certificate-authority windows-server-2012-r2

9
推荐指数
1
解决办法
3660
查看次数