PSConfig.Crescendo.psm1
# Module created by Microsoft.PowerShell.Crescendo # Version: 1.1.0 # Schema: https://aka.ms/PowerShell/Crescendo/Schemas/2022-06 # Generated at: 08/28/2023 12:04:50 class PowerShellCustomFunctionAttribute : System.Attribute { [bool]$RequiresElevation [string]$Source PowerShellCustomFunctionAttribute() { $this.RequiresElevation = $false; $this.Source = "Microsoft.PowerShell.Crescendo" } PowerShellCustomFunctionAttribute([bool]$rElevation) { $this.RequiresElevation = $rElevation $this.Source = "Microsoft.PowerShell.Crescendo" } } # Returns available errors # Assumes that we are being called from within a script cmdlet when EmitAsError is used. function Pop-CrescendoNativeError { param ([switch]$EmitAsError) while ($__CrescendoNativeErrorQueue.Count -gt 0) { if ($EmitAsError) { $msg = $__CrescendoNativeErrorQueue.Dequeue() $er = [System.Management.Automation.ErrorRecord]::new([system.invalidoperationexception]::new($msg), $PSCmdlet.Name, "InvalidOperation", $msg) $PSCmdlet.WriteError($er) } else { $__CrescendoNativeErrorQueue.Dequeue() } } } # this is purposefully a filter rather than a function for streaming errors filter Push-CrescendoNativeError { if ($_ -is [System.Management.Automation.ErrorRecord]) { $__CrescendoNativeErrorQueue.Enqueue($_) } else { $_ } } function Invoke-PSConfigProductUpgrade { [PowerShellCustomFunctionAttribute(RequiresElevation=$False)] [CmdletBinding(DefaultParameterSetName='default')] param( [Parameter()] [string]$Inplace, [Parameter()] [switch]$Wait, [Parameter()] [switch]$Force, [Parameter()] [switch]$ResetContentDefinition, [Parameter()] [switch]$KeepUserExperience, [Parameter()] [switch]$SetPassphrase ) BEGIN { $PSNativeCommandUseErrorActionPreference = $false $__CrescendoNativeErrorQueue = [System.Collections.Queue]::new() $__PARAMETERMAP = @{ Inplace = @{ OriginalName = '-inplace' OriginalPosition = '0' Position = '2147483647' ParameterType = 'string' ApplyToExecutable = $False NoGap = $False ArgumentTransform = '$args' ArgumentTransformType = 'inline' } Wait = @{ OriginalName = '-wait' OriginalPosition = '0' Position = '2147483647' ParameterType = 'switch' ApplyToExecutable = $False NoGap = $False ArgumentTransform = '$args' ArgumentTransformType = 'inline' } Force = @{ OriginalName = '-force' OriginalPosition = '0' Position = '2147483647' ParameterType = 'switch' ApplyToExecutable = $False NoGap = $False ArgumentTransform = '$args' ArgumentTransformType = 'inline' } ResetContentDefinition = @{ OriginalName = '-reghostonupgrade' OriginalPosition = '0' Position = '2147483647' ParameterType = 'switch' ApplyToExecutable = $False NoGap = $False ArgumentTransform = '$args' ArgumentTransformType = 'inline' } KeepUserExperience = @{ OriginalName = '-preserveoldusereexperience' OriginalPosition = '0' Position = '2147483647' ParameterType = 'switch' ApplyToExecutable = $False NoGap = $False ArgumentTransform = '$args' ArgumentTransformType = 'inline' } SetPassphrase = @{ OriginalName = '-passphrase' OriginalPosition = '0' Position = '2147483647' ParameterType = 'switch' ApplyToExecutable = $False NoGap = $False ArgumentTransform = '$args' ArgumentTransformType = 'inline' } } $__outputHandlers = @{ default = @{ StreamOutput = $False; Handler = 'Invoke-ParseError' } } } PROCESS { $__boundParameters = $PSBoundParameters $__defaultValueParameters = $PSCmdlet.MyInvocation.MyCommand.Parameters.Values.Where({$_.Attributes.Where({$_.TypeId.Name -eq "PSDefaultValueAttribute"})}).Name $__defaultValueParameters.Where({ !$__boundParameters["$_"] }).ForEach({$__boundParameters["$_"] = get-variable -value $_}) $__commandArgs = @() $MyInvocation.MyCommand.Parameters.Values.Where({$_.SwitchParameter -and $_.Name -notmatch "Debug|Whatif|Confirm|Verbose" -and ! $__boundParameters[$_.Name]}).ForEach({$__boundParameters[$_.Name] = [switch]::new($false)}) if ($__boundParameters["Debug"]){wait-debugger} $__commandArgs += '-cmd' $__commandArgs += 'upgrade' foreach ($paramName in $__boundParameters.Keys| Where-Object {!$__PARAMETERMAP[$_].ApplyToExecutable}| Where-Object {!$__PARAMETERMAP[$_].ExcludeAsArgument}| Sort-Object {$__PARAMETERMAP[$_].OriginalPosition}) { $value = $__boundParameters[$paramName] $param = $__PARAMETERMAP[$paramName] if ($param) { if ($value -is [switch]) { if ($value.IsPresent) { if ($param.OriginalName) { $__commandArgs += $param.OriginalName } } elseif ($param.DefaultMissingValue) { $__commandArgs += $param.DefaultMissingValue } } elseif ( $param.NoGap ) { # if a transform is specified, use it and the construction of the values is up to the transform if($param.ArgumentTransform -ne '$args') { $transform = $param.ArgumentTransform if($param.ArgumentTransformType -eq 'inline') { $transform = [scriptblock]::Create($param.ArgumentTransform) } $__commandArgs += & $transform $value } else { $pFmt = "{0}{1}" # quote the strings if they have spaces if($value -match "\s") { $pFmt = "{0}""{1}""" } $__commandArgs += $pFmt -f $param.OriginalName, $value } } else { if($param.OriginalName) { $__commandArgs += $param.OriginalName } if($param.ArgumentTransformType -eq 'inline') { $transform = [scriptblock]::Create($param.ArgumentTransform) } else { $transform = $param.ArgumentTransform } $__commandArgs += & $transform $value } } } $__commandArgs = $__commandArgs | Where-Object {$_ -ne $null} if ($__boundParameters["Debug"]){wait-debugger} if ( $__boundParameters["Verbose"]) { Write-Verbose -Verbose -Message "psconfig.exe" $__commandArgs | Write-Verbose -Verbose } $__handlerInfo = $__outputHandlers[$PSCmdlet.ParameterSetName] if (! $__handlerInfo ) { $__handlerInfo = $__outputHandlers["Default"] # Guaranteed to be present } $__handler = $__handlerInfo.Handler if ( $PSCmdlet.ShouldProcess("psconfig.exe $__commandArgs")) { # check for the application and throw if it cannot be found if ( -not (Get-Command -ErrorAction Ignore "psconfig.exe")) { throw "Cannot find executable 'psconfig.exe'" } if ( $__handlerInfo.StreamOutput ) { if ( $null -eq $__handler ) { & "psconfig.exe" $__commandArgs } else { & "psconfig.exe" $__commandArgs 2>&1| Push-CrescendoNativeError | & $__handler } } else { $result = & "psconfig.exe" $__commandArgs 2>&1| Push-CrescendoNativeError & $__handler $result } } # be sure to let the user know if there are any errors Pop-CrescendoNativeError -EmitAsError } # end PROCESS <# .DESCRIPTION Upgrade SharePoint Products using c:\> psconfig -cmd upgrade and a selection of additional parameters. .PARAMETER Inplace Perfoms an in-place upgrade (which means?). v2v as a value will perform an in-place upgrade version to version. b2b as a value will perform an in-place upgrade build to build. .PARAMETER Wait If not used, a Timer Job will be used in the background to perform the upgrade. .PARAMETER Force Stops any currently running upgrade actions and the restarts the upgrade. .PARAMETER ResetContentDefinition Reset all content to the site definition version (what ever that means). .PARAMETER KeepUserExperience Will keep the upgrade from upgrading to any new user experience available. .PARAMETER SetPassphrase Sets(?) the passphrase used to join the server farm. Must be the same on all servers. #> } function Invoke-PSConfigInstallApplicationContent { [PowerShellCustomFunctionAttribute(RequiresElevation=$False)] [CmdletBinding(DefaultParameterSetName='default')] param( ) BEGIN { $PSNativeCommandUseErrorActionPreference = $false $__CrescendoNativeErrorQueue = [System.Collections.Queue]::new() $__PARAMETERMAP = @{} $__outputHandlers = @{ default = @{ StreamOutput = $False; Handler = 'Invoke-ParseError' } } } PROCESS { $__boundParameters = $PSBoundParameters $__defaultValueParameters = $PSCmdlet.MyInvocation.MyCommand.Parameters.Values.Where({$_.Attributes.Where({$_.TypeId.Name -eq "PSDefaultValueAttribute"})}).Name $__defaultValueParameters.Where({ !$__boundParameters["$_"] }).ForEach({$__boundParameters["$_"] = get-variable -value $_}) $__commandArgs = @() $MyInvocation.MyCommand.Parameters.Values.Where({$_.SwitchParameter -and $_.Name -notmatch "Debug|Whatif|Confirm|Verbose" -and ! $__boundParameters[$_.Name]}).ForEach({$__boundParameters[$_.Name] = [switch]::new($false)}) if ($__boundParameters["Debug"]){wait-debugger} $__commandArgs += '-cmd' $__commandArgs += 'applicationcontent' $__commandArgs += '-install' foreach ($paramName in $__boundParameters.Keys| Where-Object {!$__PARAMETERMAP[$_].ApplyToExecutable}| Where-Object {!$__PARAMETERMAP[$_].ExcludeAsArgument}| Sort-Object {$__PARAMETERMAP[$_].OriginalPosition}) { $value = $__boundParameters[$paramName] $param = $__PARAMETERMAP[$paramName] if ($param) { if ($value -is [switch]) { if ($value.IsPresent) { if ($param.OriginalName) { $__commandArgs += $param.OriginalName } } elseif ($param.DefaultMissingValue) { $__commandArgs += $param.DefaultMissingValue } } elseif ( $param.NoGap ) { # if a transform is specified, use it and the construction of the values is up to the transform if($param.ArgumentTransform -ne '$args') { $transform = $param.ArgumentTransform if($param.ArgumentTransformType -eq 'inline') { $transform = [scriptblock]::Create($param.ArgumentTransform) } $__commandArgs += & $transform $value } else { $pFmt = "{0}{1}" # quote the strings if they have spaces if($value -match "\s") { $pFmt = "{0}""{1}""" } $__commandArgs += $pFmt -f $param.OriginalName, $value } } else { if($param.OriginalName) { $__commandArgs += $param.OriginalName } if($param.ArgumentTransformType -eq 'inline') { $transform = [scriptblock]::Create($param.ArgumentTransform) } else { $transform = $param.ArgumentTransform } $__commandArgs += & $transform $value } } } $__commandArgs = $__commandArgs | Where-Object {$_ -ne $null} if ($__boundParameters["Debug"]){wait-debugger} if ( $__boundParameters["Verbose"]) { Write-Verbose -Verbose -Message "psconfig.exe" $__commandArgs | Write-Verbose -Verbose } $__handlerInfo = $__outputHandlers[$PSCmdlet.ParameterSetName] if (! $__handlerInfo ) { $__handlerInfo = $__outputHandlers["Default"] # Guaranteed to be present } $__handler = $__handlerInfo.Handler if ( $PSCmdlet.ShouldProcess("psconfig.exe $__commandArgs")) { # check for the application and throw if it cannot be found if ( -not (Get-Command -ErrorAction Ignore "psconfig.exe")) { throw "Cannot find executable 'psconfig.exe'" } if ( $__handlerInfo.StreamOutput ) { if ( $null -eq $__handler ) { & "psconfig.exe" $__commandArgs } else { & "psconfig.exe" $__commandArgs 2>&1| Push-CrescendoNativeError | & $__handler } } else { $result = & "psconfig.exe" $__commandArgs 2>&1| Push-CrescendoNativeError & $__handler $result } } # be sure to let the user know if there are any errors Pop-CrescendoNativeError -EmitAsError } # end PROCESS <# .DESCRIPTION Copies shared application data to existing Web applications using c:\> psconfig -cmd applicationcontent -install #> } function Invoke-PSConfigRegisterFeatures { [PowerShellCustomFunctionAttribute(RequiresElevation=$False)] [CmdletBinding(DefaultParameterSetName='default')] param( ) BEGIN { $PSNativeCommandUseErrorActionPreference = $false $__CrescendoNativeErrorQueue = [System.Collections.Queue]::new() $__PARAMETERMAP = @{} $__outputHandlers = @{ default = @{ StreamOutput = $False; Handler = 'Invoke-ParseError' } } } PROCESS { $__boundParameters = $PSBoundParameters $__defaultValueParameters = $PSCmdlet.MyInvocation.MyCommand.Parameters.Values.Where({$_.Attributes.Where({$_.TypeId.Name -eq "PSDefaultValueAttribute"})}).Name $__defaultValueParameters.Where({ !$__boundParameters["$_"] }).ForEach({$__boundParameters["$_"] = get-variable -value $_}) $__commandArgs = @() $MyInvocation.MyCommand.Parameters.Values.Where({$_.SwitchParameter -and $_.Name -notmatch "Debug|Whatif|Confirm|Verbose" -and ! $__boundParameters[$_.Name]}).ForEach({$__boundParameters[$_.Name] = [switch]::new($false)}) if ($__boundParameters["Debug"]){wait-debugger} $__commandArgs += '-cmd' $__commandArgs += 'installfeatures' foreach ($paramName in $__boundParameters.Keys| Where-Object {!$__PARAMETERMAP[$_].ApplyToExecutable}| Where-Object {!$__PARAMETERMAP[$_].ExcludeAsArgument}| Sort-Object {$__PARAMETERMAP[$_].OriginalPosition}) { $value = $__boundParameters[$paramName] $param = $__PARAMETERMAP[$paramName] if ($param) { if ($value -is [switch]) { if ($value.IsPresent) { if ($param.OriginalName) { $__commandArgs += $param.OriginalName } } elseif ($param.DefaultMissingValue) { $__commandArgs += $param.DefaultMissingValue } } elseif ( $param.NoGap ) { # if a transform is specified, use it and the construction of the values is up to the transform if($param.ArgumentTransform -ne '$args') { $transform = $param.ArgumentTransform if($param.ArgumentTransformType -eq 'inline') { $transform = [scriptblock]::Create($param.ArgumentTransform) } $__commandArgs += & $transform $value } else { $pFmt = "{0}{1}" # quote the strings if they have spaces if($value -match "\s") { $pFmt = "{0}""{1}""" } $__commandArgs += $pFmt -f $param.OriginalName, $value } } else { if($param.OriginalName) { $__commandArgs += $param.OriginalName } if($param.ArgumentTransformType -eq 'inline') { $transform = [scriptblock]::Create($param.ArgumentTransform) } else { $transform = $param.ArgumentTransform } $__commandArgs += & $transform $value } } } $__commandArgs = $__commandArgs | Where-Object {$_ -ne $null} if ($__boundParameters["Debug"]){wait-debugger} if ( $__boundParameters["Verbose"]) { Write-Verbose -Verbose -Message "psconfig.exe" $__commandArgs | Write-Verbose -Verbose } $__handlerInfo = $__outputHandlers[$PSCmdlet.ParameterSetName] if (! $__handlerInfo ) { $__handlerInfo = $__outputHandlers["Default"] # Guaranteed to be present } $__handler = $__handlerInfo.Handler if ( $PSCmdlet.ShouldProcess("psconfig.exe $__commandArgs")) { # check for the application and throw if it cannot be found if ( -not (Get-Command -ErrorAction Ignore "psconfig.exe")) { throw "Cannot find executable 'psconfig.exe'" } if ( $__handlerInfo.StreamOutput ) { if ( $null -eq $__handler ) { & "psconfig.exe" $__commandArgs } else { & "psconfig.exe" $__commandArgs 2>&1| Push-CrescendoNativeError | & $__handler } } else { $result = & "psconfig.exe" $__commandArgs 2>&1| Push-CrescendoNativeError & $__handler $result } } # be sure to let the user know if there are any errors Pop-CrescendoNativeError -EmitAsError } # end PROCESS <# .DESCRIPTION Registers any SharePoint Products and Technologies features on this server with the server farm using c:\> psconfig -cmd installfeatures #> } function Invoke-PSConfigSecureResourceFiles { [PowerShellCustomFunctionAttribute(RequiresElevation=$False)] [CmdletBinding(DefaultParameterSetName='default')] param( ) BEGIN { $PSNativeCommandUseErrorActionPreference = $false $__CrescendoNativeErrorQueue = [System.Collections.Queue]::new() $__PARAMETERMAP = @{} $__outputHandlers = @{ default = @{ StreamOutput = $False; Handler = 'Invoke-ParseError' } } } PROCESS { $__boundParameters = $PSBoundParameters $__defaultValueParameters = $PSCmdlet.MyInvocation.MyCommand.Parameters.Values.Where({$_.Attributes.Where({$_.TypeId.Name -eq "PSDefaultValueAttribute"})}).Name $__defaultValueParameters.Where({ !$__boundParameters["$_"] }).ForEach({$__boundParameters["$_"] = get-variable -value $_}) $__commandArgs = @() $MyInvocation.MyCommand.Parameters.Values.Where({$_.SwitchParameter -and $_.Name -notmatch "Debug|Whatif|Confirm|Verbose" -and ! $__boundParameters[$_.Name]}).ForEach({$__boundParameters[$_.Name] = [switch]::new($false)}) if ($__boundParameters["Debug"]){wait-debugger} $__commandArgs += '-cmd' $__commandArgs += 'secureresources' foreach ($paramName in $__boundParameters.Keys| Where-Object {!$__PARAMETERMAP[$_].ApplyToExecutable}| Where-Object {!$__PARAMETERMAP[$_].ExcludeAsArgument}| Sort-Object {$__PARAMETERMAP[$_].OriginalPosition}) { $value = $__boundParameters[$paramName] $param = $__PARAMETERMAP[$paramName] if ($param) { if ($value -is [switch]) { if ($value.IsPresent) { if ($param.OriginalName) { $__commandArgs += $param.OriginalName } } elseif ($param.DefaultMissingValue) { $__commandArgs += $param.DefaultMissingValue } } elseif ( $param.NoGap ) { # if a transform is specified, use it and the construction of the values is up to the transform if($param.ArgumentTransform -ne '$args') { $transform = $param.ArgumentTransform if($param.ArgumentTransformType -eq 'inline') { $transform = [scriptblock]::Create($param.ArgumentTransform) } $__commandArgs += & $transform $value } else { $pFmt = "{0}{1}" # quote the strings if they have spaces if($value -match "\s") { $pFmt = "{0}""{1}""" } $__commandArgs += $pFmt -f $param.OriginalName, $value } } else { if($param.OriginalName) { $__commandArgs += $param.OriginalName } if($param.ArgumentTransformType -eq 'inline') { $transform = [scriptblock]::Create($param.ArgumentTransform) } else { $transform = $param.ArgumentTransform } $__commandArgs += & $transform $value } } } $__commandArgs = $__commandArgs | Where-Object {$_ -ne $null} if ($__boundParameters["Debug"]){wait-debugger} if ( $__boundParameters["Verbose"]) { Write-Verbose -Verbose -Message "psconfig.exe" $__commandArgs | Write-Verbose -Verbose } $__handlerInfo = $__outputHandlers[$PSCmdlet.ParameterSetName] if (! $__handlerInfo ) { $__handlerInfo = $__outputHandlers["Default"] # Guaranteed to be present } $__handler = $__handlerInfo.Handler if ( $PSCmdlet.ShouldProcess("psconfig.exe $__commandArgs")) { # check for the application and throw if it cannot be found if ( -not (Get-Command -ErrorAction Ignore "psconfig.exe")) { throw "Cannot find executable 'psconfig.exe'" } if ( $__handlerInfo.StreamOutput ) { if ( $null -eq $__handler ) { & "psconfig.exe" $__commandArgs } else { & "psconfig.exe" $__commandArgs 2>&1| Push-CrescendoNativeError | & $__handler } } else { $result = & "psconfig.exe" $__commandArgs 2>&1| Push-CrescendoNativeError & $__handler $result } } # be sure to let the user know if there are any errors Pop-CrescendoNativeError -EmitAsError } # end PROCESS <# .DESCRIPTION Perform SharePoint file and registry key security enforcement using c:\> psconfig -cmd secureresources #> } function Invoke-PSConfigRegisterServices { [PowerShellCustomFunctionAttribute(RequiresElevation=$False)] [CmdletBinding(DefaultParameterSetName='default')] param( ) BEGIN { $PSNativeCommandUseErrorActionPreference = $false $__CrescendoNativeErrorQueue = [System.Collections.Queue]::new() $__PARAMETERMAP = @{} $__outputHandlers = @{ default = @{ StreamOutput = $False; Handler = 'Invoke-ParseError' } } } PROCESS { $__boundParameters = $PSBoundParameters $__defaultValueParameters = $PSCmdlet.MyInvocation.MyCommand.Parameters.Values.Where({$_.Attributes.Where({$_.TypeId.Name -eq "PSDefaultValueAttribute"})}).Name $__defaultValueParameters.Where({ !$__boundParameters["$_"] }).ForEach({$__boundParameters["$_"] = get-variable -value $_}) $__commandArgs = @() $MyInvocation.MyCommand.Parameters.Values.Where({$_.SwitchParameter -and $_.Name -notmatch "Debug|Whatif|Confirm|Verbose" -and ! $__boundParameters[$_.Name]}).ForEach({$__boundParameters[$_.Name] = [switch]::new($false)}) if ($__boundParameters["Debug"]){wait-debugger} $__commandArgs += '-cmd' $__commandArgs += 'services' $__commandArgs += '-install' foreach ($paramName in $__boundParameters.Keys| Where-Object {!$__PARAMETERMAP[$_].ApplyToExecutable}| Where-Object {!$__PARAMETERMAP[$_].ExcludeAsArgument}| Sort-Object {$__PARAMETERMAP[$_].OriginalPosition}) { $value = $__boundParameters[$paramName] $param = $__PARAMETERMAP[$paramName] if ($param) { if ($value -is [switch]) { if ($value.IsPresent) { if ($param.OriginalName) { $__commandArgs += $param.OriginalName } } elseif ($param.DefaultMissingValue) { $__commandArgs += $param.DefaultMissingValue } } elseif ( $param.NoGap ) { # if a transform is specified, use it and the construction of the values is up to the transform if($param.ArgumentTransform -ne '$args') { $transform = $param.ArgumentTransform if($param.ArgumentTransformType -eq 'inline') { $transform = [scriptblock]::Create($param.ArgumentTransform) } $__commandArgs += & $transform $value } else { $pFmt = "{0}{1}" # quote the strings if they have spaces if($value -match "\s") { $pFmt = "{0}""{1}""" } $__commandArgs += $pFmt -f $param.OriginalName, $value } } else { if($param.OriginalName) { $__commandArgs += $param.OriginalName } if($param.ArgumentTransformType -eq 'inline') { $transform = [scriptblock]::Create($param.ArgumentTransform) } else { $transform = $param.ArgumentTransform } $__commandArgs += & $transform $value } } } $__commandArgs = $__commandArgs | Where-Object {$_ -ne $null} if ($__boundParameters["Debug"]){wait-debugger} if ( $__boundParameters["Verbose"]) { Write-Verbose -Verbose -Message "psconfig.exe" $__commandArgs | Write-Verbose -Verbose } $__handlerInfo = $__outputHandlers[$PSCmdlet.ParameterSetName] if (! $__handlerInfo ) { $__handlerInfo = $__outputHandlers["Default"] # Guaranteed to be present } $__handler = $__handlerInfo.Handler if ( $PSCmdlet.ShouldProcess("psconfig.exe $__commandArgs")) { # check for the application and throw if it cannot be found if ( -not (Get-Command -ErrorAction Ignore "psconfig.exe")) { throw "Cannot find executable 'psconfig.exe'" } if ( $__handlerInfo.StreamOutput ) { if ( $null -eq $__handler ) { & "psconfig.exe" $__commandArgs } else { & "psconfig.exe" $__commandArgs 2>&1| Push-CrescendoNativeError | & $__handler } } else { $result = & "psconfig.exe" $__commandArgs 2>&1| Push-CrescendoNativeError & $__handler $result } } # be sure to let the user know if there are any errors Pop-CrescendoNativeError -EmitAsError } # end PROCESS <# .DESCRIPTION Registers the local SharePoint services with the farm using c:\> psconfig -cmd services -install #> } function Invoke-PSConfigSafeProductUpgrade { [PowerShellCustomFunctionAttribute(RequiresElevation=$False)] [CmdletBinding(DefaultParameterSetName='default')] param( ) BEGIN { $PSNativeCommandUseErrorActionPreference = $false $__CrescendoNativeErrorQueue = [System.Collections.Queue]::new() $__PARAMETERMAP = @{} $__outputHandlers = @{ default = @{ StreamOutput = $False; Handler = 'Invoke-ParseError' } } } PROCESS { $__boundParameters = $PSBoundParameters $__defaultValueParameters = $PSCmdlet.MyInvocation.MyCommand.Parameters.Values.Where({$_.Attributes.Where({$_.TypeId.Name -eq "PSDefaultValueAttribute"})}).Name $__defaultValueParameters.Where({ !$__boundParameters["$_"] }).ForEach({$__boundParameters["$_"] = get-variable -value $_}) $__commandArgs = @() $MyInvocation.MyCommand.Parameters.Values.Where({$_.SwitchParameter -and $_.Name -notmatch "Debug|Whatif|Confirm|Verbose" -and ! $__boundParameters[$_.Name]}).ForEach({$__boundParameters[$_.Name] = [switch]::new($false)}) if ($__boundParameters["Debug"]){wait-debugger} $__commandArgs += '-cmd' $__commandArgs += 'upgrade' $__commandArgs += '-inplace' $__commandArgs += 'b2b' $__commandArgs += '-wait' $__commandArgs += '-force' $__commandArgs += '-cmd' $__commandArgs += 'applicationcontent' $__commandArgs += '-install' $__commandArgs += '-cmd' $__commandArgs += 'installfeatures' $__commandArgs += '-cmd' $__commandArgs += 'secureresources' $__commandArgs += '-cmd' $__commandArgs += 'services' $__commandArgs += '-install' foreach ($paramName in $__boundParameters.Keys| Where-Object {!$__PARAMETERMAP[$_].ApplyToExecutable}| Where-Object {!$__PARAMETERMAP[$_].ExcludeAsArgument}| Sort-Object {$__PARAMETERMAP[$_].OriginalPosition}) { $value = $__boundParameters[$paramName] $param = $__PARAMETERMAP[$paramName] if ($param) { if ($value -is [switch]) { if ($value.IsPresent) { if ($param.OriginalName) { $__commandArgs += $param.OriginalName } } elseif ($param.DefaultMissingValue) { $__commandArgs += $param.DefaultMissingValue } } elseif ( $param.NoGap ) { # if a transform is specified, use it and the construction of the values is up to the transform if($param.ArgumentTransform -ne '$args') { $transform = $param.ArgumentTransform if($param.ArgumentTransformType -eq 'inline') { $transform = [scriptblock]::Create($param.ArgumentTransform) } $__commandArgs += & $transform $value } else { $pFmt = "{0}{1}" # quote the strings if they have spaces if($value -match "\s") { $pFmt = "{0}""{1}""" } $__commandArgs += $pFmt -f $param.OriginalName, $value } } else { if($param.OriginalName) { $__commandArgs += $param.OriginalName } if($param.ArgumentTransformType -eq 'inline') { $transform = [scriptblock]::Create($param.ArgumentTransform) } else { $transform = $param.ArgumentTransform } $__commandArgs += & $transform $value } } } $__commandArgs = $__commandArgs | Where-Object {$_ -ne $null} if ($__boundParameters["Debug"]){wait-debugger} if ( $__boundParameters["Verbose"]) { Write-Verbose -Verbose -Message "psconfig.exe" $__commandArgs | Write-Verbose -Verbose } $__handlerInfo = $__outputHandlers[$PSCmdlet.ParameterSetName] if (! $__handlerInfo ) { $__handlerInfo = $__outputHandlers["Default"] # Guaranteed to be present } $__handler = $__handlerInfo.Handler if ( $PSCmdlet.ShouldProcess("psconfig.exe $__commandArgs")) { # check for the application and throw if it cannot be found if ( -not (Get-Command -ErrorAction Ignore "psconfig.exe")) { throw "Cannot find executable 'psconfig.exe'" } if ( $__handlerInfo.StreamOutput ) { if ( $null -eq $__handler ) { & "psconfig.exe" $__commandArgs } else { & "psconfig.exe" $__commandArgs 2>&1| Push-CrescendoNativeError | & $__handler } } else { $result = & "psconfig.exe" $__commandArgs 2>&1| Push-CrescendoNativeError & $__handler $result } } # be sure to let the user know if there are any errors Pop-CrescendoNativeError -EmitAsError } # end PROCESS <# .DESCRIPTION Applies all commands recommended to use after patching SharePoint using c:\> psconfig -cmd upgrade -inplace b2b -wait -force -cmd applicationcontent -install -cmd installfeatures -cmd secureresources -cmd services -install #> } function Invoke-ParseError { [CmdletBinding()] param ( [Parameter()] [string[]]$InputString ) <# $logs = $InputString -like '*located*' | # get all lines containing a log file location foreach {# and extract the log file path $_ -replace "`n",'' -replace "`r",'' -split 'located' | select -index 1 } | foreach { $_ -split ' ' | select -Index 2 } #> $InputString -match 'error|exception|throw|invalid|fail|diagnostic|missing' | where {$_ -notlike '*success*'} | foreach { write-error -Message $_ } } |