Назад | Перейти на главную страницу

Скрипт Powershell удаляет элементы

Я изучаю PowerShell, поэтому для меня это все в новинку. Я наткнулся на этот пост: https://www.thelazyadministrator.com/2020/01/26/deploy-intune-applications-with-powershell-and-azure-blob-storage/ Я выделил локальную часть местоположения, потому что хочу полагаться исключительно на хранилище BLOB-объектов.

Я пробовал использовать это для Office Pro Plus, но похоже, что это не работает. Что он делает в настоящее время: он загружает необходимый zip из нашего хранилища BLOB-объектов и помещает его в папку в% 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"
}

Здесь вам не нужно 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"