有没有办法从Windows资源管理器启动PowerShell在一个特定的文件夹,例如右键单击一个文件夹,并有一个选项,如“打开PowerShell在这个文件夹”?

每天我第一次运行MSBuild时,都要更改项目文件夹的目录,这真的很烦人。

我有一个.zip文件,需要使用Powershell解压缩其全部内容。我在这么做,但似乎并不奏效:

$shell = New-Object -ComObject shell.application
$zip = $shell.NameSpace("C:\a.zip")
MkDir("C:\a")
foreach ($item in $zip.items()) {
  $shell.Namespace("C:\a").CopyHere($item)
}

怎么了?目录C:\a仍然为空。

PowerShell 1.0可以创建类似Unix的硬链接和软链接吗?

如果这不是内置的,有人能告诉我一个网站,有一个ps1脚本模仿这个吗?

恕我直言,这是任何优秀shell的必要功能。:)

在PowerShell中是否有一种简单的方法来计时命令的执行,就像Linux中的'time'命令一样? 我想到了这个:

$s=Get-Date; .\do_something.ps1 ; $e=Get-Date; ($e - $s).TotalSeconds

但我想要简单点的,比如

time .\do_something.ps1

我有一个.ps1文件,我想在其中定义自定义函数。

假设文件名为MyFunctions。Ps1,内容如下:

Write-Host "Installing functions"
function A1
{
    Write-Host "A1 is running!"
}
Write-Host "Done"

为了运行这个脚本并理论上注册A1函数,我导航到.ps1文件所在的文件夹并运行该文件:

.\MyFunctions.ps1

这个输出:

Installing functions
Done

然而,当我尝试调用A1时,我只是得到一个错误,说明没有该名称的命令/函数:

The term 'A1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling
 of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:3
+ A1 <<<<
    + CategoryInfo          : ObjectNotFound: (A1:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

我一定误解了PowerShell的一些概念。我不能在脚本文件中定义函数吗?

注意,我已经将我的执行策略设置为“remotessigned”。我知道运行。ps1文件时,在文件名前加一个点:.\myFile.ps1

我正在所有的文件夹中查找一个文件。

Copyforbuild.bat在很多地方都有,我想递归搜索。

$File = "V:\Myfolder\**\*.CopyForbuild.bat"

如何在PowerShell中做到这一点?

如何在PowerShell中使用如下命令并将其拆分为多行?

&"C:\Program Files\IIS\Microsoft Web Deploy\msdeploy.exe" -verb:sync -source:contentPath="c:\workspace\xxx\master\Build\_PublishedWebsites\xxx.Web" -dest:contentPath="c:\websites\xxx\wwwroot\,computerName=192.168.1.1,username=administrator,password=xxx"

我已经开始学习Angular了,但我注意到,每当我在Windows中执行Angular命令时,powershell都会给我一个错误:

ng new new-app

or

ng serve

这是我得到的错误:

ng : File C:\Users\< username >\AppData\Roaming\npm\ng.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
+ ng serve
+ ~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

附注:我在cmd中尝试这些命令,它可以工作。

我有一个包含多对一关系的jpa持久化对象模型:一个Account有多个transaction。一个事务有一个帐户。

下面是一段代码:

@Entity
public class Transaction {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @ManyToOne(cascade = {CascadeType.ALL},fetch= FetchType.EAGER)
    private Account fromAccount;
....

@Entity
public class Account {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @OneToMany(cascade = {CascadeType.ALL},fetch= FetchType.EAGER, mappedBy = "fromAccount")
    private Set<Transaction> transactions;

我能够创建Account对象,向其添加事务,并正确地持久化Account对象。但是,当我创建一个事务,使用现有的已经持久化的帐户,并持久化的事务,我得到一个异常:

导致:org.hibernate.PersistentObjectException:传递给persist: com.paulsanwald.Account的分离实体 org.hibernate.event.internal.DefaultPersistEventListener.onPersist (DefaultPersistEventListener.java: 141)

因此,我能够持久化一个包含事务的Account,但不能持久化一个具有Account的Transaction。我认为这是因为帐户可能没有附加,但这段代码仍然给了我相同的异常:

if (account.getId()!=null) {
    account = entityManager.merge(account);
}
Transaction transaction = new Transaction(account,"other stuff");
 // the below fails with a "detached entity" message. why?
entityManager.persist(transaction);

如何正确地保存与已经持久化的帐户对象相关联的事务?

我想在PowerShell脚本中通过设置标志输出变量和值,并在整个脚本中查看数据。

我该怎么做呢?

例如,PowerShell与下面的PHP代码有什么等价之处?

echo "filesizecounter: " . $filesizecounter