Greetings I am not an expert on bigfix, However I am trying to run this script via BigFix to run in place upgrade for clients
Here is what I am getting
Completed // Disable wow64 redirection on x64 OSes
Completed action uses wow64 redirection {not x64 of operating system}
Completed // CREATEFILE
Completed createfile until EOF
Completed
Failed function Write-Log {
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[string]$Message
)
try {
if (!(Test-Path -path ([System.IO.Path]::GetDirectoryName($LogFilePath)))) {
New-Item -ItemType Directory -Path ([System.IO.Path]::GetDirectoryName($LogFilePath))
}
$DateTime = Get-Date -Format âyyyy-MM-dd HH:mm:ssâ
Add-Content -Value "$DateTime - $Message" -Path $LogFilePath
}
catch {
Write-Error $_.Exception.Message
}
}
Function CheckIfElevated() {
Write-Log "Info: Checking for elevated permissions..."
if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
[Security.Principal.WindowsBuiltInRole] "Administrator")) {
Write-Log "ERROR: Insufficient permissions to run this script. Open the PowerShell console as an administrator and run this script again."
return $false
}
else {
Write-Log "Info: Code is running as administrator â go on executing the script..."
return $true
}
}
# Main
try {
# Declarations
[string]$DownloadDir = 'C:\Temp\Windows_FU\packages'
[string]$LogDir = 'C:\Temp\Windows_FU\Logs'
[string]$LogFilePath = [string]::Format("{0}\{1}_{2}.log", $LogDir, "$(get-date -format `"yyyyMMdd_hhmmsstt`")", $MyInvocation.MyCommand.Name.Replace(".ps1", ""))
[string]$Url = 'https://go.microsoft.com/fwlink/?LinkID=799445'
[string]$UpdaterBinary = "$($DownloadDir)\Win10Upgrade.exe"
[string]$UpdaterArguments = '/quietinstall /skipeula /auto upgrade /copylogs $LogDir'
[System.Net.WebClient]$webClient = New-Object System.Net.WebClient
# Here the music starts playing ..
Write-Log -Message ([string]::Format("Info: Script init - User: {0} Machine {1}", $env:USERNAME, $env:COMPUTERNAME))
Write-Log -Message ([string]::Format("Current Windows Version: {0}", [System.Environment]::OSVersion.ToString()))
# Check if script is running as admin and elevated
if (!(CheckIfElevated)) {
Write-Log -Message "ERROR: Will terminate!"
break
}
# Check if folders exis
if (!(Test-Path $DownloadDir)) {
New-Item -ItemType Directory -Path $DownloadDir
}
if (!(Test-Path $LogDir)) {
New-Item -ItemType Directory -Path $LogDir
}
if (Test-Path $UpdaterBinary) {
Remove-Item -Path $UpdaterBinary -Force
}
# Download the Windows Update Assistant
Write-Log -Message "Will try to download Windows Update Assistant.."
$webClient.DownloadFile($Url, $UpdaterBinary)
# If the Update Assistant exists -> create a process with argument to initialize the update process
if (Test-Path $UpdaterBinary) {
Start-Process -FilePath $UpdaterBinary -ArgumentList $UpdaterArguments -Wait
Write-Log "Fired and forgotten?"
}
else {
Write-Log -Message ([string]::Format("ERROR: File {0} does not exist!", $UpdaterBinary))
}
}
catch {
Write-Log -Message $_.Exception.Message
Write-Error $_.Exception.Message
}
EOF
delete WinUpdate.ps1
move __createfile WinUpdate.ps1 "C:\temp\WinUpdate.ps1"
Please use the âcodeâ formatting when pasting your Actionscript or results so we can read it in the forum, otherwise all of the formatting is messed up. I fixed your post above.
I havenât gone through all your PowerShell, but at first glance every â{â needs to be escaped as â{{â so BigFix doesnât treat it as a relevance substitution.
1 Like
Thank you Jason,
Sorry I am not familiar with the Formatting in here,
I have changed the â{â and got and exit code â1â
Here is the new Fixlet
//Create Script
createfile until EOF
Update Windows using Windows Update Assistant
Script Version 1.0 - 2022-11-4
function Write-Log {{
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[string]$Message
)
try {{
if (!(Test-Path -path ([System.IO.Path]::GetDirectoryName($LogFilePath)))) {{
New-Item -ItemType Directory -Path ([System.IO.Path]::GetDirectoryName($LogFilePath))
}}
$DateTime = Get-Date -Format âyyyy-MM-dd HH:mm:ssâ
Add-Content -Value "$DateTime - $Message" -Path $LogFilePath
}
catch {{
Write-Error $_.Exception.Message
}
}
Function CheckIfElevated() {{
Write-Log "Info: Checking for elevated permissions..."
if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
[Security.Principal.WindowsBuiltInRole] "Administrator")) {{
Write-Log "ERROR: Insufficient permissions to run this script. Open the PowerShell console as an administrator and run this script again."
return $false
}
else {{
Write-Log "Info: Code is running as administrator â go on executing the script..."
return $true
}
}
Main
try {{
Declarations
[string]$DownloadDir = 'C:\WinUpgrade\Windows_FU\packages'
[string]$LogDir = 'C:\WinUpgrade\Logs'
[string]$LogFilePath = [string]::Format("{0}\{1}_{2}.log", $LogDir, "$(get-date -format `"yyyyMMdd_hhmmsstt`")", $MyInvocation.MyCommand.Name.Replace(".ps1", ""))
[string]$Url = 'https://go.microsoft.com/fwlink/?linkid=2171764'
[string]$UpdaterBinary = "$($DownloadDir)\Win11Upgrade.exe"
[string]$UpdaterArguments = '/quietinstall /skipeula /auto upgrade /copylogs $LogDir'
[System.Net.WebClient]$webClient = New-Object System.Net.WebClient
Write-Log -Message ([string]::Format("Info: Script init - User: {0} Machine {1}", $env:USERNAME, $env:COMPUTERNAME))
Write-Log -Message ([string]::Format("Current Windows Version: {0}", [System.Environment]::OSVersion.ToString()))
Check if script is running as admin and elevated
if (!(CheckIfElevated)) {{
Write-Log -Message "ERROR: Will terminate!"
break
}}
# Check if folders exis
if (!(Test-Path $DownloadDir)) {{
New-Item -ItemType Directory -Path $DownloadDir
}}
if (!(Test-Path $LogDir)) {{
New-Item -ItemType Directory -Path $LogDir
}}
if (Test-Path $UpdaterBinary) {{
Remove-Item -Path $UpdaterBinary -Force
}}
Download the Windows Update Assistant
Write-Log -Message "Will try to download Windows Update Assistant.."
$webClient.DownloadFile($Url, $UpdaterBinary)
If the Update Assistant exists -> create a process with argument to initialize the update process
if (Test-Path $UpdaterBinary) {{
Start-Process -FilePath $UpdaterBinary -ArgumentList $UpdaterArguments -Wait
Write-Log "Updated launched"
}}
else {{
Write-Log -Message ([string]::Format("ERROR: File {0} does not exist!", $UpdaterBinary))
}
}
catch {{
Write-Log -Message $_.Exception.Message
Write-Error $_.Exception.Message
}
EOF
copy __createfile "C:\Temp\WinUpdate11.ps1"
//Run The Script
waithidden C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -file "C:\Temp\WinUpdate11.ps
In the forum post window, highlight all of your code and click the âcode formatâ button -
// This is my actionscript
// There is more like it
1 Like
The exit code â1â is coming from the PowerShell interpreter.
Iâm not well-versed in PowerShellâŚdo those first couple of lines need to be commented? Does this powershell work if you run it outside of BigFix?
I do not need the Comments. Yes it Does run
Is it generating any of the log or error output? Iâm not sureâŚwhether the âLocalSystemâ account that BigFix runs under will pass your check for Administrator rights
The PS file is created but the the script wonât run
I tried it on one of my machines, the PS1 file does get createdâŚdoes your âC:\Tempâ folder exist? The âcopyâ command requires that the C:\Temp target directory already exists.
Before performing the copy, you could just add
folder create "c:\Temp"
which will create the folder if itâs missing or skip if it already exists.
The Folder is in there but it is called temp not Temp not sure if thatâs an issue
I donât believe the copy is case-sensitive, but what you had in the most recent post does create the ps1 file for me. Is there something else in the action thatâs failing?
Nothings is failing
Completed //Create Script
Completed createfile until EOF
Completed
Completed # Update Windows using Windows Update Assistant
Completed # Script Version 1.0 - 2022-11-4
Completed
Completed function Write-Log {{
Completed [CmdletBinding()]
Completed param (
Completed [Parameter(Mandatory)]
Completed [string]$Message
Completed )
Completed
Completed try {{
Completed if (!(Test-Path -path ([System.IO.Path]::GetDirectoryName($LogFilePath)))) {{
Completed New-Item -ItemType Directory -Path ([System.IO.Path]::GetDirectoryName($LogFilePath))
Completed }}
Completed $DateTime = Get-Date -Format âyyyy-MM-dd HH:mm:ssâ
Completed Add-Content -Value "$DateTime - $Message" -Path $LogFilePath
Completed }
Completed catch {{
Completed Write-Error $_.Exception.Message
Completed }
Completed }
Completed Function CheckIfElevated() {{
Completed Write-Log "Info: Checking for elevated permissions..."
Completed if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
Completed [Security.Principal.WindowsBuiltInRole] "Administrator")) {{
Completed Write-Log "ERROR: Insufficient permissions to run this script. Open the PowerShell console as an administrator and run this script again."
Completed return $false
Completed }
Completed else {{
Completed Write-Log "Info: Code is running as administrator â go on executing the script..."
Completed return $true
Completed }
Completed }
Completed
Completed # Main
Completed
Completed try {{
Completed # Declarations
Completed [string]$DownloadDir = 'C:\WinUpgrade\Windows_FU\packages'
Completed [string]$LogDir = 'C:\WinUpgrade\Logs'
Completed [string]$LogFilePath = [string]::Format("{0}\{1}_{2}.log", $LogDir, "$(get-date -format `"yyyyMMdd_hhmmsstt`")", $MyInvocation.MyCommand.Name.Replace(".ps1", ""))
Completed [string]$Url = 'https://go.microsoft.com/fwlink/?linkid=2171764'
Completed [string]$UpdaterBinary = "$($DownloadDir)\Win11Upgrade.exe"
Completed [string]$UpdaterArguments = '/quietinstall /skipeula /auto upgrade /copylogs $LogDir'
Completed [System.Net.WebClient]$webClient = New-Object System.Net.WebClient
Completed
Completed # Here the music starts playing ..
Completed Write-Log -Message ([string]::Format("Info: Script init - User: {0} Machine {1}", $env:USERNAME, $env:COMPUTERNAME))
Completed Write-Log -Message ([string]::Format("Current Windows Version: {0}", [System.Environment]::OSVersion.ToString()))
Completed
Completed # Check if script is running as admin and elevated
Completed if (!(CheckIfElevated)) {{
Completed Write-Log -Message "ERROR: Will terminate!"
Completed break
Completed }}
Completed
Completed # Check if folders exis
Completed if (!(Test-Path $DownloadDir)) {{
Completed New-Item -ItemType Directory -Path $DownloadDir
Completed }}
Completed if (!(Test-Path $LogDir)) {{
Completed New-Item -ItemType Directory -Path $LogDir
Completed }}
Completed if (Test-Path $UpdaterBinary) {{
Completed Remove-Item -Path $UpdaterBinary -Force
Completed }}
Completed # Download the Windows Update Assistant
Completed Write-Log -Message "Will try to download Windows Update Assistant.."
Completed $webClient.DownloadFile($Url, $UpdaterBinary)
Completed
Completed # If the Update Assistant exists -> create a process with argument to initialize the update process
Completed if (Test-Path $UpdaterBinary) {{
Completed Start-Process -FilePath $UpdaterBinary -ArgumentList $UpdaterArguments -Wait
Completed Write-Log "Updated launched"
Completed }}
Completed else {{
Completed Write-Log -Message ([string]::Format("ERROR: File {0} does not exist!", $UpdaterBinary))
Completed }
Completed }
Completed catch {{
Completed Write-Log -Message $_.Exception.Message
Completed Write-Error $_.Exception.Message
Completed }
Completed EOF
Completed copy __createfile "C:\Temp\WinUpdate11.ps1"
Completed //Run The Script
Completed waithidden C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -file "C:\Temp\WinUpdate11.ps1"
is there another way to run PS scripts in BigFix ?
Yes, either 10.0.3 or 10.0.4 added âPowerShellâ as a script type, you should be able to select that from the drop-down menu in the action editor tab of the task.
1 Like
Jason Thank you, I have tried that, but it fails without any exit codes, Let me copy the
Oh, in âActionScriptâ type, missed a couple of places that had open-curly-brackets
[string]$LogFilePath = [string]::Format(â{0}{1}_{2}.logâ, $LogDir, "$(get-date
Write-Log -Message ([string]::Format(âERROR: File {0} does not exist!â,
1 Like
Iâm most concerned about where you say the powershell script isnât being created at all. Iâd try with a simpler case, just remove all of the powershell script and replace it with a placeholder. Donât even try to use âwaithiddenâ to execute it, just create a dummy script and save it to the output file first.
1 Like
Jason, I am sorry I meant the script is created, but it wonât run. I see the PS file in âC:\Tempâ directory. it wonât execute it
Oh, ok.
And you still have the 'wow64 redirection" turned off?
1 Like
Correct yes it is turned off