Sharepoint Powershell with CAML<nativehr>0x80070057</nativehr> - powershell

I've was trying to solve this error looking other posts, but i can't figure out what i'm doing wrong.
In a powershell of Sharepoint 2010 i want to delete all items of a list using the next CAML Query.
$query.Query = #'
<Where>
<Eq>
<FieldRef Name="Mes"/>
<Value Type="Text">2017/01</Value>
</Eq>
</Where>
'#
$items = $list.GetItems($query)
$items
This give me the following error
Excepción al intentar enumerar la colección "<nativehr>0x80070057</nativehr><nativestack></nativestack>".
En línea: 1 Carácter: 7
+ $items <<<<
+ CategoryInfo : NotSpecified: (:) [], ExtendedTypeSystemException
+ FullyQualifiedErrorId : ExceptionInGetEnumerator
[Mes] is a calculated column with text output.
I'm sure i'm doing it wrong. Can you help me please?

Related

PowerShell Output English

I read English Output
, where it gives this function to force PowerShell output in English
function Set-PowerShellUICulture {
param([Parameter(Mandatory=$true)]
[string]$Name)
process {
$culture = [System.Globalization.CultureInfo]::CreateSpecificCulture($Name)
$assembly = [System.Reflection.Assembly]::Load("System.Management.Automation")
$type = $assembly.GetType("Microsoft.PowerShell.NativeCultureResolver")
$field = $type.GetField("m_uiCulture", [Reflection.BindingFlags]::NonPublic -bor [Reflection.BindingFlags]::Static)
$field.SetValue($null, $culture)
}
}
This only seems to work half-way, as line 2 here contains Norwegian "Ingen Tilgang", which means "Access Denied".
get-acl *
get-acl : Ingen tilgang
At line:1 char:1
+ get-acl *
+ ~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-Acl], UnauthorizedAccessException
+ FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.GetAclCommand
Any other way I can force output to be en English?;)

Problems with whitespaces on Powershell

I have a Powershell script to remove items on a folder:
Get-ChildItem D:\FUNDACIÓN CB\Pedro Corchero Murga\Info de vídeos\Proyectos\* | Remove-Item -Recurse
The problem is that I'm having issues with the path because it have whitespaces and gives me this error:
Get-ChildItem : No se encuentra ningún parámetro de posición que acepte el argumento 'Corchero'.
En línea: 1 Carácter: 1
+ Get-ChildItem D:\FUNDACIÓN CB\Pedro Corchero Murga\Info de vídeos\Pro ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-ChildItem], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
How I can fix it?
Simply add quotes " " to the path:
Get-ChildItem "D:\FUNDACION CB\........"

Logparser query for netapp logs

I'm trying to write a log parser for NetApp logs using PowerShell.
The script goes as below:
$logparser = "c:\program files (x86)\Log Parser 2.2\logparser.exe"
$query = “SELECT TimeCreated SystemTime,EventID,EventName,Computer,ComputerUUID,EventCategoryName,SourceName,EventData Data INTO D:\Temp\audit_EUPNPSVM-SCM-FC-NAS_D2018-01-09-T10-32-49_0000000000.csv FROM D:\Temp\audit_EUPNPSVM-SCM-FC-NAS_D2018-01-09-T10-32-49_0000000000.evtx" WHERE EventData(Data Name= 'ObjectName')
& $logparser -i:evt -o:csv $query
$ps.WaitForExit()
$ps.ExitCode;
I get error:
PS C:\> C:\script\test2.ps1
At C:\script\test2.ps1:2 char:279
+ ... 00000000.evtx" WHERE EventData(Data Name= 'ObjectName')
+ ~~~~~
Unexpected token 'WHERE' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken

Powershell named parameters error

I'm tring to do the following:
$Feature = "OWAEnabled"
Set-CasMailbox Admin -$($Feature) $False
But i get each time this error:
Set-CASMailbox : Es wurde kein Positionsparameter gefunden, der das Argument "-OWAEnabled:True" akzeptiert.
In Zeile:1 Zeichen:2
+ set-casmailbox Administrator -$($Feature):$True
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-CASMailbox], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.Exchange.Management.RecipientTasks.SetCASMailbox
Can someone help me?
Thanks a lot
This will work, though not the prettiest:
$Feature = "OWAEnabled"
$c = "Set-CasMailbox Admin -$($Feature):`$False"
Invoke-Expression $c

What is the need of using 'put' method to set the value of a property through powershell

I tried the following cases :
$Localhst = $env:ComputerName;
$comp = [ADSI]('WinNT://'+$Localhst+',computer');
$user = $comp.Create('User', 'account24');
$user.SetPassword('Welcome1$');
$user.Description = "Created through powershell script client";
$user.SetInfo();
I am getting the following exception :
Error Occurred while executing powershell command Exception calling "SetInfo" with "0" argument(s): "The account already exists. (Exception from HRESULT: 0x8007
08B0)"
But when I am using put method it is working fine :
$Localhst = $env:ComputerName;
$comp = [ADSI]('WinNT://'+$Localhst+',computer');
$user = $comp.Create('User', 'account24');
$user.SetPassword('Welcome1$');
$user.put("Description","Created through powershell script client");
$user.SetInfo();
What is the difference between using put method to set the value and setting the value directly?
I use the same code but receive a different error
$Localhst = $env:ComputerName;
$comp = [ADSI]('WinNT://'+$Localhst+',computer');
$user = $comp.Create('User', 'account24');
$user.SetPassword('Welcome1$');
$user.Description = "Created through powershell script client";
$user.SetInfo();
Produce
$user.SetInfo();
Exception lors de la définition de « Description » : « Impossible de définir la propriété Value de l'objet PSMemberInfo de type « System.Management.Automation.PSMethod ». »
Au caractère Ligne:5 : 1
+ $user.Description = "Created through powershell script client";
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], SetValueInvocationException
+ FullyQualifiedErrorId : ExceptionWhenSetting
Exception lors de l'appel de « SetInfo » avec « 0 » argument(s) : « Accès refusé.
 »
Au caractère Ligne:6 : 1
+ $user.SetInfo();
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : CatchFromBaseAdapterMethodInvokeTI
The message is in French but it significate unable to define the property like this. But if I run it as administrator it create the user (with no description)