我在Server 2008 R2上成功启用了PSRemoting.我可以使用主机名作为目标在同一网络中进行远程pssession.
当我尝试从任何计算机(在网络内或从其他网络(例如通过VPN))使用IP地址作为目标时,我失败了.我希望能够通过我的VPN连接使用远程处理,因为无法解析主机名,因此我必须使用IP地址.
我不想在我的hosts文件中添加名称,因为我们的客户端上有一些其他服务器具有相同的dns-name,我不想删除并再次插入name-ip-address-association然后再次.
我希望有人能告诉我如何通过IP调用psremoting-target.
编辑:更具体地说,我希望能够运行:
Enter-PSSession -Computername 192.168.123.123 -credentials $cred
Run Code Online (Sandbox Code Playgroud)
但是,如果我将主机名传递给" -Computername" ,我只能运行该命令
Edit2:
当我尝试使用ip而不是主机名(来自内部网络)登录时,我收到了错误消息:
Enter-PSSession : Connecting to remote server failed with the following error message : The WinRM client cannot process
the request. Default authentication may be used with an IP address under the following conditions: the transport is HT
TPS or the destination is in the TrustedHosts list, and explicit credentials are provided. Use winrm.cmd to configure T
rustedHosts. Note that computers …Run Code Online (Sandbox Code Playgroud) 例如:如果我跑notepad.exe c:\autoexec.bat,
我怎样才能c:\autoexec.bat在Get-Process notepadPowerShell中?
或者我怎样才能c:\autoexec.bat在Process.GetProcessesByName("notepad");C#中?
我目前正在用C#编写一个库,并且正在使用PowerShell在某些情况下快速测试它.但是,这使我无法重新构建项目,因为PowerShell显然仍然打开了DLL.
有没有办法在添加后再次卸载DLL Add-Type?文档似乎没有关于这一点的线索,而明显的候选者将是Remove-Type(它不存在 - 无论如何只有一个命令Type作为其名词).关闭PowerShell并执行导航到构建目录的所有内容并在每次要重建时再次添加类型都很麻烦.
我在Windows 7 x64虚拟机中运行PowerShell.我在主机上有一个共享文件夹映射为网络驱动器(Z :).当我正常运行PS时,我可以正常访问该驱动器,但如果我以"管理员"的身份运行它,它会告诉我:
Set-Location : Cannot find drive. A drive with the name 'Z' does not exist.
At line:1 char:13
+ Set-Location <<<< Z:
+ CategoryInfo : ObjectNotFound: (Z:String) [Set-Location], DriveNotFoundException
+ FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.SetLocationCommand
Run Code Online (Sandbox Code Playgroud)
如何以管理员身份访问网络驱动器?
当我尝试调试我的Windows 8应用程序并且已经在另一个用户帐户上安装了一个副本时,我一直在遇到这个问题:
DEP0700:应用程序注册失败.另一位用户已经安装了此应用程序的打包版本.未打包的版本无法取代此版本.冲突的包是{{{PackageName}}},它由CN = {{{Certificate Stuff}}}发布.(0x80073cf9)
有时我可以登录或要求其他人登录计算机并卸载应用程序.或者,我可以更改应用程序名称/ ID,但是一个并不总是可行而另一个是有风险的(我不想将已更改的应用程序ID签入源代码控制).
必须有一些方法来卸载它.也许是PowerShell脚本?
powershell windows-8 windows-runtime windows-store windows-store-apps
我需要找到产品GUID对于安装MSI文件,以进行维护,如补丁,卸载,也为审计目的.
要么我不理解MSDN上的文档或文档不正确.
if($user_sam -ne "" -and $user_case -ne "")
{
Write-Host "Waaay! Both vars have values!"
}
else
{
Write-Host "One or both of the vars are empty!"
}
Run Code Online (Sandbox Code Playgroud)
我希望你理解我试图输出的内容.我想填充$ user_sam和$ user_case以访问第一个语句!
我对PowerShell比较陌生,并且有一个脚本可以读取一个配置文件,该文件会产生一组名称值对,我希望将它们作为参数传递给第二个PowerShell脚本中的函数.
我不知道在设计时将在此配置文件中放置哪些参数,所以就在我需要调用第二个PowerShell脚本时,我基本上只有一个变量具有第二个脚本的路径,第二个脚本变量,它是要传递给路径变量中标识的脚本的参数数组.
因此,包含第二个脚本($ scriptPath)路径的变量可能具有如下值:
"c:\the\path\to\the\second\script.ps1"
Run Code Online (Sandbox Code Playgroud)
包含参数($ argumentList)的变量可能类似于:
-ConfigFilename "doohickey.txt" -RootDirectory "c:\some\kind\of\path" -Max 11
Run Code Online (Sandbox Code Playgroud)
如何从这种状态到使用$ argumentList中的所有参数执行script.ps1?
我希望来自第二个脚本的任何write-host命令对于调用此第一个脚本的控制台是可见的.
我尝试过dot-sourcing,Invoke-Command,Invoke-Expression和Start-Job,但我还没有找到一种不会产生错误的方法.
例如,我认为最简单的第一条路线是尝试按如下方式调用Start-Job:
Start-Job -FilePath $scriptPath -ArgumentList $argumentList
Run Code Online (Sandbox Code Playgroud)
...但是由于此错误而失败:
System.Management.Automation.ValidationMetadataException:
Attribute cannot be added because it would cause the variable
ConfigFilename with value -ConfigFilename to become invalid.
Run Code Online (Sandbox Code Playgroud)
...在这种情况下,"ConfigFilename"是第二个脚本定义的参数列表中的第一个参数,我的调用显然试图将其值设置为"-ConfigFilename",这显然是为了按名称标识参数,没有设定它的价值.
我错过了什么?
编辑:
好的,这是一个名为invokee.ps1的文件中的待调用脚本的模型
Param(
[parameter(Mandatory=$true)]
[alias("rc")]
[string]
[ValidateScript( {Test-Path $_ -PathType Leaf} )]
$ConfigurationFilename,
[alias("e")]
[switch]
$Evaluate,
[array]
[Parameter(ValueFromRemainingArguments=$true)]
$remaining)
function sayHelloWorld()
{
Write-Host "Hello, everybody, the config file is <$ConfigurationFilename>."
if ($ExitOnErrors)
{
Write-Host "I should …Run Code Online (Sandbox Code Playgroud) powershell parameter-passing command-line-arguments invoke-command start-job
当我尝试在 VS Code 终端上运行 ionic 命令时ionic serve,出现以下错误。
我怎样才能解决这个问题?
ionic : File C:\Users\Lakshan\AppData\Roaming\npm\ionic.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see
about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ ~~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
Run Code Online (Sandbox Code Playgroud)