小编use*_*227的帖子

Powershell Zip文件夹内容

我知道在使用Powershell压缩文件时已经涉及很多,但是我找不到能够完全满足我需要的方法.

我希望能够将文件夹和文件压缩到.zip文件夹中,而不需要在zip文件中包含父文件夹.所以例如我有一个名为STUFF的文件夹,其中包含文件/文件夹,我想将其压缩到一个名为STUFF.zip的文件夹中.这个文件夹结构将是STUFF.zip>文件/文件夹NOT STUFF.zip> STUFF>文件/文件夹,因为我目前使用此代码...

function CountZipItems(
[__ComObject] $zipFile)
{
If ($zipFile -eq $null)
{
    Throw "Value cannot be null: zipFile"
}

Write-Host ("Counting items in zip file (" + $zipFile.Self.Path + ")...")

[int] $count = CountZipItemsRecursive($zipFile)

Write-Host ($count.ToString() + " items in zip file (" `
    + $zipFile.Self.Path + ").")

return $count
}

function CountZipItemsRecursive(
[__ComObject] $parent)
{
If ($parent -eq $null)
{
    Throw "Value cannot be null: parent"
}

[int] $count = 0

$parent.Items() |
    ForEach-Object {
        $count += …
Run Code Online (Sandbox Code Playgroud)

powershell zip

8
推荐指数
3
解决办法
9425
查看次数

Powershell打开文件路径与空间

我的PS脚本我希望能够通过执行以下操作在另一个PS实例中运行另一个脚本:

$filepath = Resolve-Path "destruct.ps1"

start-process powershell.exe "$filepath"
Run Code Online (Sandbox Code Playgroud)

destruct.ps1与此脚本位于同一文件夹中

但是,当在包含空格的位置("C:\ My Scripts \")中运行此脚本时,我将收到以下错误:

术语"C:\ My"未被识别为cmdlet,函数,可操作程序或脚本文件.验证该术语,然后重试.

我知道通过使用带有Invoke-Expression方法的'&'来解决这个问题,我怎么能这样做但是通过使用start-process方法?

非常感谢您的帮助!

powershell start-process

8
推荐指数
2
解决办法
3万
查看次数

标签 统计

powershell ×2

start-process ×1

zip ×1