我正在尝试在以工作组模式运行的 Windows 2008 R2 服务器上启用 Powershell 远程处理。
我在 PowerShell 控制台中运行了命令 Enable-PSRemoting。
PS C:\Windows\system32> Enable-PSRemoting
WinRM Quick Configuration Running command "Set-WSManQuickConfig" to enable this machine for remote management through WinRM service This includes:
1. Starting or restarting (if already started) the WinRM service
2. Setting the WinRM service type to auto start
3. Creating a listener to accept requests on any IP address
4. Enabling firewall exception for WS-Management traffic (for http only).
Do you want to continue? [Y] Yes [A] …Run Code Online (Sandbox Code Playgroud) 剧本相当直接。只是尝试启动一堆 Windows 服务。在目标机器上执行本地工作正常。当通过 PsExec 完成时,该脚本实际上也能正常执行,直到我在 CMD 提示符下按“回车”键,它才会返回。这是一个问题,因为这是从 TeamCity 调用的,它使 Agent 挂起,等待 PsExec 返回。
我尝试了以下方法:
exit和exit 0< NUL根据此 SF 问题中的答案,在 PsExec 调用的末尾添加一个>标准输出重定向这就是我实际调用 psexec 的方式:
psexec \\target -u domain\username -p password powershell c:\path\script.ps1
Run Code Online (Sandbox Code Playgroud)
无论我做什么,它都会挂起,直到我在 cmd 提示符下本地。按回车后,我收到消息:
powershell exited on target with error code 0.
Run Code Online (Sandbox Code Playgroud) 我需要用powershell解压缩一个文件。我见过每个人这样做的典型方法是使用脚本自动化 shell。
$shellApplication = new-object -com shell.application
$zipPackage = $shellApplication.NameSpace($zipfilename)
$destinationFolder = $shellApplication.NameSpace($destination)
$destinationFolder.CopyHere($zipPackage.Items())
Run Code Online (Sandbox Code Playgroud)
这对我不起作用,因为服务器核心没有外壳,所以没有自动化。这会导致 E_FAIL COM 错误。
Powershell 似乎无法自行完成,如果我参加第 3 方,我必须首先想办法将实用程序加载到服务器上。7-Zip 是我的首选,但我似乎无法编写下载和安装它的脚本。Sourceforge 不断向我吐槽 HTML 文件。
如何在 Server 2012 Core 中完全编写解压 zip 文件的脚本?
我尝试为我的 powershell 环境创建一个终极设置。
我用一堆语句创建了“Microsoft.PowerShell_profiles.ps1”来设置我的默认配置文件。
但是,当我开始 PowerShell 会话时,我得到:
File C:\Documents and Settings\xxx\My Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 cannot be loaded.
The file C:\Documents and Settings\xxx\My Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 is not digitally signed. The script will not execute on the system.
如何在特定驱动器(D:、E:、...)上启用卷影复制并使用 Powershell 设置计划?
我只需要一些提示如何开始。
“须藤!!” 在 *nix shell 中以管理员权限调用先前执行的命令。PowerShell 中是否有等价物?
我正在尝试使用 Windows Powershell 查找两个文件夹结构的内容差异。我使用了以下方法来确保文件名相同,但是此方法不会告诉我文件的内容是否相同:
$firstFolder = Get-ChildItem -Recurse folder1
$secondFolder = Get-ChildItem -Recurse folder2
Compare-Object -ReferenceObject $firstFolder -DifferenceObject $secondFolder
Run Code Online (Sandbox Code Playgroud)
此 ServerFault 问题中描述的技术适用于比较单个文件,但这些文件夹包含数百个不同深度的文件。
解决方案不一定需要告诉我文件中的具体内容不同 - 只是它们是不同的。我对元数据的差异不感兴趣,例如日期,我已经知道它们是不同的。
我编写了这个简短的 powershell 脚本,将计算机重命名为 MDT 任务序列的一部分:
Import-Module ActiveDirectory
$AdminUsername = 'domain.com\administrator'
$AdminPassword = 'password' | ConvertTo-SecureString -asPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList $AdminUsername, $AdminPassword
$Domain = Get-ADDomainController –DomainName domain.com -Discover -NextClosestSite
$Site = $Domain.Site
$DomainComputer = Get-WmiObject Win32_BIOS
$Serial = $DomainComputer.SerialNumber
$Computername = $Site + "-" + $Serial
Rename-Computer -NewName $Computername -DomainCredential $cred
Run Code Online (Sandbox Code Playgroud)
当 MDT 运行此任务时,它以本地管理员身份运行它。尝试加载 AD 模块时出现以下错误。
Warning: Error initializing default drive: 'The server has rejected the client credentials.'.
Run Code Online (Sandbox Code Playgroud)
当以域管理员身份登录时,我可以在任务序列结束后从机器导入模块,但不能以机器的本地管理员身份登录。有没有办法以域管理员身份运行MDT任务序列或者在任务序列期间提升本地管理员的权限?
预先感谢您提供的任何帮助,
MX
更新:10/13/2015
我决定不再在我的 MDT 脚本中使用 AD 模块,并在发布此内容后不久设计了另一种完成此操作的方法。我使用 AD …
我有一个 Azure 文件共享,并希望在我的 Azure VM 中使用它 - 在使用 cmdkey 在 VM 上保留凭据并使用网络使用挂载之后。这是通过在 Windows Server 2012 R2 上的本地 Powershell 会话中运行这些命令来测试的。
但我需要将此步骤添加到 Azure 部署脚本中。Azure Powershell 脚本从我的笔记本电脑运行,连接到 Azure 订阅并使用大量变量从头开始构建 VM。
想出使用 Invoke-Command 将变量从 Azure Powershell 脚本传递到新创建的 VM 上的远程 Powershell 会话。
$Session = New-PSSession -ConnectionUri $Uri -Credential $DomainCredential
$ScriptBlockContent = {
Param ($Arg1,$Arg2,$Arg3)
cmdkey /add:$Arg1 /user:$Arg2 /pass:$Arg3}
Invoke-Command -Session $Session -ScriptBlock $ScriptBlockContent -ArgumentList ($Share,$AccountName,$Key)
Run Code Online (Sandbox Code Playgroud)
和错误:
PS C:\> Invoke-Command -Session $Session -ScriptBlock $ScriptBlockContent -ArgumentList ($Share,$AccountName,$Key)
CMDKEY: Credentials cannot be saved from this logon session.
Run Code Online (Sandbox Code Playgroud)
替换成cmdkey …
PowerShell Web 访问允许您选择身份验证类型。默认情况下,它使用的值为Default,最终为Negotiate。我已经设置了 CredSSP 以允许使用 CredSSP 登录到 PSWA 服务器本身,以便网络身份验证在会话内工作(避免双跳问题,无需在整个网络上委托凭据)。
无论如何,我希望 CredSSP 成为登录页面上的默认选项。
查看 IIS 中 PSWA Web 应用程序的配置选项,可以设置多个值来覆盖默认值。
其中一个被称为defaultAuthenticationTypewhich is a stringbut 被设置为0.
这似乎是正确的设置,但我无法让它工作。
如果我检查登录网页,我可以看到选择框具有以下值:
0 Default
1 Basic
2 Negotiate
4 CredSSP
5 Digest
6 Kerberos
Run Code Online (Sandbox Code Playgroud)
3 不见了。
JosefZ发现这3是NegotiateWithImplicitCredential根据此页面,但对我而言,在 Windows PowerShell 5.1.15063.966 上,枚举中缺少名称/值。
如果我设置defaultAuthenticationType为一个数字,则网页默认为一个新选项:
7 Admin Specified
Run Code Online (Sandbox Code Playgroud)
我试过3and 4,但没有一个有效。使用 Kerberos 进行登录,不使用 CredSSP。
如果我手动选择 CredSSP,它会按预期工作。
如果我设置defaultAuthentcationType为类似 的字符串CredSSP …