Quantcast
Channel: AutoSPInstaller
Viewing all articles
Browse latest Browse all 2279

Created Unassigned: AddResourcesLink function is broken [22215]

$
0
0
When AutoSPInstaller reaches the point that it calls AddResourcesLink and the item already exist. It will throw the following

```
Exception : System.Management.Automation.RuntimeException: Cannot convert value "URL" to type
"System.Int32". Error: "Input string was not in a correct format." --->
System.Management.Automation.PSInvalidCastException: Cannot convert value "URL" to type
"System.Int32". Error: "Input string was not in a correct format." --->
System.FormatException: Input string was not in a correct format.
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number,
NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
at System.ComponentModel.Int32Converter.FromString(String value, NumberFormatInfo
formatInfo)
at System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context,
CultureInfo culture, Object value)
--- End of inner exception stack trace ---
at System.Management.Automation.LanguagePrimitives.ConvertStringToInteger(Object
valueToConvert, Type resultType, Boolean recursion, PSObject originalValueToConvert,
IFormatProvider formatProvider, TypeTable backupTable)
at CallSite.Target(Closure , CallSite , Object , String , String )
at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0,
T1 arg1, T2 arg2)
at System.Management.Automation.Interpreter.DynamicInstruction`4.Run(InterpretedFrame frame)
at
System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame
frame)
--- End of inner exception stack trace ---
at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext
funcContext, Exception exception)
at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame
frame)
at
System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame
frame)
at
System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame
frame)
at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0)
at System.Management.Automation.ScriptBlock.InvokeWithPipeImpl(ScriptBlockClauseToInvoke
clauseToInvoke, Boolean createLocalScope, Dictionary`2 functionsToDefine, List`1
variablesToDefine, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object
input, Object scriptThis, Pipe outputPipe, InvocationInfo invocationInfo, Object[] args)
at System.Management.Automation.ScriptBlock.<>c__DisplayClassa.<InvokeWithPipe>b__8()
at System.Management.Automation.Runspaces.RunspaceBase.RunActionIfNoRunningPipelinesWithThre
adCheck(Action action)
at System.Management.Automation.ScriptBlock.InvokeWithPipe(Boolean useLocalScope,
Dictionary`2 functionsToDefine, List`1 variablesToDefine, ErrorHandlingBehavior
errorHandlingBehavior, Object dollarUnder, Object input, Object scriptThis, Pipe outputPipe,
InvocationInfo invocationInfo, Object[] args)
at System.Management.Automation.ScriptBlock.InvokeUsingCmdlet(Cmdlet contextCmdlet, Boolean
useLocalScope, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input,
Object scriptThis, Object[] args)
at Microsoft.PowerShell.Commands.ForEachObjectCommand.ProcessRecord()
at System.Management.Automation.CommandProcessor.ProcessRecord()
TargetObject :
CategoryInfo : InvalidArgument: (:) [ForEach-Object], RuntimeException
FullyQualifiedErrorId : InvalidCastFromStringToInteger,Microsoft.PowerShell.Commands.ForEachObjectCommand
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at AddResourcesLink, D:\03-SharePoint\01-AutoSPInstaller2013\AutoSPInstallerFunctions.ps1:
line 7458
at <ScriptBlock>, D:\03-SharePoint\01-AutoSPInstaller2013\AutoSPInstallerFunctions.ps1: line
5061
at CreateEnterpriseSearchServiceApp,
D:\03-SharePoint\01-AutoSPInstaller2013\AutoSPInstallerFunctions.ps1: line 4614
at Setup-Services, D:\03-SharePoint\01-AutoSPInstaller2013\AutoSPInstallerMain.ps1: line 227
at <ScriptBlock>, D:\03-SharePoint\01-AutoSPInstaller2013\AutoSPInstallerMain.ps1: line 409
at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {}
PSMessageDetails :
```


changing the function to the following will ensure that there are no duplicates of the resources link and fixing the issue above
```
Function AddResourcesLink([string]$title,[string]$url)
{
$centraladminapp = Get-SPWebApplication -IncludeCentralAdministration | ? {$_.IsAdministrationWebApplication}
$centraladminurl = $centraladminapp.Url
$centraladmin = (Get-SPSite $centraladminurl)

$item = $centraladmin.RootWeb.Lists["Resources"].Items | Where { $_.Name -eq $title }

If ($item -eq $null )
{
$item = $centraladmin.RootWeb.Lists["Resources"].Items.Add();
}
else
{
$item.Delete();
$item.Update();
$item = $centraladmin.RootWeb.Lists["Resources"].Items.Add();
}

$url = $centraladminurl + $url + ", $title";
$item["URL"] = $url;
$item.Update();
}
```

Viewing all articles
Browse latest Browse all 2279

Trending Articles



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