I have this issue deploy Sharepoint using Powershell:
I have Windows Service C# with credentials for user UserInstallerMoss. Windows Service execute an EXE Console Aplicaction C# with credentials UserInstallerMoss. EXE Console Aplicaction executes powershell.exe with credentials UserInstallerMoss.
UserinstallerMOss is Farm Administrator, local administrator, WSS_ADMIN_WPG group...
Powershell functions returns $true value:
$ok = IsCurrentUserAdmin $ok = IsCurrentUserAdmin2 Fails in this line:
$fileCollection.Delete($file.Name) Call to the function Add-ItemsToLib
$siteAssets = Get-SPSite -identity $urlAssetsSite $webAssets = $siteAssets.OpenWeb() Write-Host "Uploading images to images library... Debug: imageslistName: $imageslistName - imagesDirectory: $imagesDirectory " Add-ItemsToLib $webAssets $imageslistName $imagesDirectory UPDATE
Note: Finally, I discover that script ps1 works if I use without Test-Connection cmdlet.
In the script ps1, there was Test-Connection cmdlet for testing:
$Servidor = $env:ComputerName if (Test-Connection -ComputerName $Servidor -Count 1 -Quiet) { WriteTraceForTrans ("Test connection to server successful. user: {0}, Server: {1}, Hostname: {2}`r`n" -f $env:USERNAME, $Servidor, (hostname)) } Full error:
Exception calling "Delete" with "1" argument(s): "0x8 0070005OWSSVR.DLL: (unresolved symbol, module offset=000 000000014A330) at 0x000007FB679BA330 Microsoft.SharePoint.Library.ni.dll: (unresolved symbol, module offset=000000000 00BE9B6) at 0x000007FB6AF0E9B6 Microsoft.SharePoint.ni.dll: (unresolved symbol, module offset=0000000002B0111A) at 0x000007FB7216111A Microsoft.SharePoint.ni.dll: (unresolved symbol, module offset=0000000002BC3FF0) at 0x000007FB72223FF0 Microsoft.SharePoint.ni.dll: (unresolved symbol, module offset=000000000310E5DF) at 0x000007FB7276E5DF Access denied
Powershell functions:
function Add-ItemsToLib($web, [string] $listName, [string] $Path) { $list = $web.Lists[$listName] $fileCollection = $list.RootFolder.Files $files = get-childItem $Path foreach ($file in $files) { $fn = $file.Name $stream = $file.OpenRead() $f = $fileCollection | Where { $_.Name -eq $file.Name } if ($f -ne $null) { Write-Host -f Red "UserName: $env:username" `r`n $ok = IsCurrentUserAdmin Write-Host -f Red "IsCurrentUserAdmin: $ok" `r`n $ok = IsCurrentUserAdmin2 Write-Host -f Red "IsCurrentUserAdmin2: $ok" `r`n $fileCollection.Delete($file.Name) } $uploaded = $fileCollection.Add($file.Name, $stream, $TRUE) $uploaded.CheckIn("") $uploaded.Publish("") $uploaded.Approve("") if ($stream) {$stream.Dispose()} } } Function IsCurrentUserAdmin { $ident = [Security.Principal.WindowsIdentity]::GetCurrent() foreach ( $groupIdent in $ident.Groups ) { if ( $groupIdent.IsValidTargetType([Security.Principal.SecurityIdentifier]) ) { $groupSid = $groupIdent.Translate([Security.Principal.SecurityIdentifier]) if ( $groupSid.IsWellKnown("AccountAdministratorSid") -or $groupSid.IsWellKnown("BuiltinAdministratorsSid")) { return $TRUE } } } return $FALSE } Function IsCurrentUserAdmin2 { $user = [Security.Principal.WindowsIdentity]::GetCurrent(); (New-Object Security.Principal.WindowsPrincipal $user).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator) }