Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

help: debugging script

$
0
0

Hi,

i'm new in powershell scripting and i met some pb with my script:

I simplified the  script (https://gallery.technet.microsoft.com/office/PowerShell-to-InstallUninst-0536b17b)  to deploy office 2013 using GPO.

But i always have the same pb: when i run it, it doesn't take care of the options (it seems like it run with setup.exe /?)

here is the script:

#Office 2013 x64

$ProductId='Office15.PROPLUS'
$SourcePath='dfs path'
$AdminFile='dfs path + .MSP'
$LogPath='dfs path'

Function Add-LogEntry ( [String]$Path ,[String]$Message)
{
    Write-Verbose -Message $Message
    # Only write log entry if a path was specified
    If ( $Path -ne '' ) {
        Add-Content -Path $Path -Value "$(Get-Date): $Message"
    } # ( $Path -ne '' )
} # Function Add-LogEntry

# If a Log Path was specified get up a log file name to write to.
If ($LogPath -eq '') {
    [String]$LogFile = ''
} else {
    [String]$LogFile = Join-Path -Path $LogPath -ChildPath "$($ENV:computername).txt"
}

# Is this Office Product already Installed?
[Boolean]$Installed = $False

If ( $env:PROCESSOR_ARCHITECTURE -eq 'AMD64' ) {
    # Operating system is AMD64

    If ( Test-Path -Path "HKLM:\SOFTWARE\WOW6432NODE\Microsoft\Windows\CurrentVersion\Uninstall\$ProductId" ) {
        # 32-bit Office is installed.
        [Boolean]$Installed = $True
    } # ( Test-Path -Path "HKLM:\SOFTWARE\WOW6432NODE\Microsoft\Windows\CurrentVersion\Uninstall\$ProductId" )

} # ( $env:PROCESSOR_ARCHITECTURE -eq 'AMD64' )


 If (-not $Installed) {
    # Sort out the command that will be used to uninstall the product.
    [String]$Command="$(Join-Path -Path $SourcePath -ChildPath 'setup.exe')"
    #If ($AdminFile -ne '') {
        #[String]$Command+=" /adminfile $AdminFile"
    #}

    Add-LogEntry -Path $LogFile -Message "Install $ProductId using $Command started."
   #If ($PSCmdlet.ShouldProcess("Install $ProductId using $Command started")) {
        # Call the product Install.& $Command " /adminfile $AdminFile" 2>&1
        [Int]$ErrorCode = $LASTEXITCODE
   #} # ShouldProcess
    If ($ErrorCode -eq 0) {
        Add-LogEntry -Path $LogFile -Message "Install $ProductId using $Command completed successfully."
    } Else {
        Add-LogEntry -Path $LogFile -Message "Install $ProductId using $Command failed with error code $ErrorCode and message: $Error"
    } # ($ErrorCode -eq 0)
} Else {
    Write-Verbose -Message "$ProductId is already installed."
} # (-not $Installed)

I think the pb comes from the quotes. I tried many changes without success.

Thanks for your help,

Y.


Viewing all articles
Browse latest Browse all 21975

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>