Powershell 脚本正在删除项目

Powershell 脚本正在删除项目

我正在学习 powershell,所以这对我来说都是新的。我偶然看到了这篇文章:https://www.thelazyadministrator.com/2020/01/26/deploy-intune-applications-with-powershell-and-azure-blob-storage/ 我精简了位置的本地部分,因为我只想依赖于 blob 存储。

我尝试将它用于 Office Pro Plus,但似乎不起作用。它目前的作用是:从我们的 Blob 存储下载所需的 zip 文件并将其放在 %appdata% 文件夹中,然后开始提取它们。当接近提取过程时,它会中断并开始删除所有已提取的文件。

我似乎无法解决这个问题......这是我当前对脚本的迭代:

param (
    [System.String]$ZipSourceFiles      = "url to zip",
    [system.string]$IntuneProgramDir    = "$env:APPDATA\Intune",
    [System.String]$FullEXEDir          = "$IntuneProgramDir\Intune\setup.exe",
    [System.String]$ZipLocation         = "$IntuneProgramDir\office.zip"
)
    #Start download of the source files from Azure Blob to the network cache location
    Start-BitsTransfer -Source $ZipSourceFiles -Destination $ZipLocation

    #Check to see if the local cache directory is present
    If ((Test-Path -Path $IntuneProgramDir) -eq $False)
    {
        #Create the local cache directory
        New-Item -ItemType Directory $IntuneProgramDir -Force -Confirm:$False
    }

    #Copy the binaries from the network cache to the local computer cache
    Copy-Item $TempNetworkZip -Destination $IntuneProgramDir  -Force

    #Extract the install binaries
    Expand-Archive -Path $ZipLocation -DestinationPath $IntuneProgramDir -Force

    #Install the program
    Start-Process "$FullEXEDir" -ArgumentList " /S /v/qn"
Else {
    #Check to see if the local cache directory is present
    If ((Test-Path -Path $IntuneProgramDir) -eq $False)
    {
        #Create the local cache directory
        New-Item -ItemType Directory $IntuneProgramDir -Force -Confirm:$False
    }

    #Copy the installer binaries from the network cache location to the local computer cache
    Copy-Item $TempNetworkZip -Destination $IntuneProgramDir  -Force

    #Extract the install binaries
    Expand-Archive -Path $ZipLocation -DestinationPath $IntuneProgramDir -Force

    #Install the program
    Start-Process "$FullEXEDir" -ArgumentList " /S /v/qn"
}

答案1

这里不需要 if-else。尝试:

  param (
    [System.String]$ZipSourceFiles      = "url to zip",
    [system.string]$IntuneProgramDir    = "$env:APPDATA\Intune",
    [System.String]$FullEXEDir          = "$IntuneProgramDir\Intune\setup.exe",
    [System.String]$ZipLocation         = "$IntuneProgramDir\office.zip"
)

Start-BitsTransfer -Source $ZipSourceFiles -Destination $ZipLocation

 #Check to see if the local cache directory is present
    If ((Test-Path -Path $IntuneProgramDir) -eq $False)
    {
        #Create the local cache directory
        New-Item -ItemType Directory $IntuneProgramDir -Force -Confirm:$False
    }


    #Extract the install binaries
    Expand-Archive -Path $ZipLocation -DestinationPath $IntuneProgramDir -Force

    #Install the program
    Start-Process "$FullEXEDir" -ArgumentList " /S /v/qn"

相关内容