Problems with whitespaces on Powershell - 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\........"

Related

Set EntityReference attribute to not working Microsoft.Xrm.Data.PowerShell

I cannot update a theme by PowerShell using Microsoft.Xrm.Data.PowerShell.
The following code is not working:
#Get Theme
$res = Get-CrmRecords -Conn $connection -EntityLogicalName theme -FilterAttribute name -FilterOperator eq -FilterValue $nameOfTheme -Fields themeid, name, logoid, isdefaulttheme, logotooltip, navbarbackgroundcolor, navbarshelfcolor, headercolor, globallinkcolor, selectedlinkeffect, hoverlinkeffect, processcontrolcolor, defaultentitycolor, defaultcustomentitycolor, controlshade, controlborder
$ImportedTheme = $res.CrmRecords[0]
#Get Resource web
$resLogo = Get-CrmRecords -Conn $connection -EntityLogicalName webresource -FilterAttribute name -FilterOperator eq -FilterValue "LogoName"
$ImportedLogo = $resLogo.CrmRecords[0]
$ERLogo = (New-CrmEntityReference -EntityLogicalName webresource -Id $ImportedLogo.webresourceid)
#Update Theme
$ImportedTheme.logoid = $ERLogo
Set-CrmRecord -Conn $connection -CrmRecord $ImportedTheme
This will given an error:
Impossible d'appeler une méthode dans une expression Null.
Au caractère C:\Users\il...ll\Microsoft.Xrm.Data.PowerShell.psm1:628 : 16
+ if($crmFieldValue -eq $null)
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation : (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Le cast spécifié n'est pas valide. Au caractère
C:\Users\il...ll\Microsoft.Xrm.Data.PowerShell.psm1:773 : 9
+ throw $conn.LastCrmException
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], InvalidCastException
+ FullyQualifiedErrorId : Le cast spécifié n'est pas valide.
I think the problem comes from this verification in this part of code of Xrm.Data.PowerShell:
if($crmFieldValue -eq $null) { Write-Host "$crmFieldValue -eq $null"
$newfield.Type = [Microsoft.Xrm.Tooling.Connector.CrmFieldType]::Raw $value = $null }
I cannot find a solution. Do you have any idea?

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

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?

nested mkdir inside directory with spaces

This command:
mkdir "watermelon fun"\example
Outputs the following:
PS C:\Users\Andrés\temp> mkdir "watermelon fun"\example
mkdir : No se encuentra ningún parámetro de posición que acepte el argumento '\example'.
En línea: 1 Carácter: 1
+ mkdir "watermelon fun"\example
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [mkdir], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,mkdir
Is there a way you can create a nested directory, being one of these a multiple word directory?
You have to surround the complete path with quotes:
mkdir "watermelon fun\example"
Consider using the Join-Path cmdlet to combine a path.
$path = join-path 'watermelon fun' 'example'
New-Item -Path $path -ItemType Directory -Force

Powershell: FCIV script error: "Cannot find path because it does not exist"

I am new to PowerShell, so I may have missed something simple. I am trying to run a file checksum for Start-PsFCIV, outlined here.
My attempt is below, where I have also tried excluding the -Path parameter, as well as using relative/absolute paths.
PS C:\Users\Lucas\Downloads> Start-PsFCIV -Path C:\Users\Lucas\Downloads\DXSDK_Jun10.exe -HashAlgorithm SHA1
Set-Location : Cannot find path 'C:\Users\Lucas\Downloads\DXSDK_Jun10.exe' because it does not exist.
At C:\Scripts\PsFCIV_2.5.ps1:227 char:3
+ Set-Location -LiteralPath $path
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\Users\Lucas\Downloads\DXSDK_Jun10.exe:String) [Set-Location], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand
Test-Path : Cannot bind argument to parameter 'LiteralPath' because it is an empty string.
At C:\Scripts\PsFCIV_2.5.ps1:280 char:32
+ if (!(Test-Path -LiteralPath $XML)) {return New-Object PsFCIV.FCIV}
+ ~~~~
+ CategoryInfo : InvalidData: (:) [Test-Path], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.TestPathCommand
__fromxml : Input XML file is not valid FCIV XML file.
At C:\Scripts\PsFCIV_2.5.ps1:511 char:9
+ $sum = __fromxml $xml
+ ~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,__fromxml
Exception setting "VerboseForegroundColor": "Cannot convert value "-1" to type "System.Windows.Media.Color". Error: "Invalid cast from 'System.ConsoleColor' to 'System.Windows.Media.Color'.""
At C:\Scripts\PsFCIV_2.5.ps1:607 char:4
+ $host.PrivateData.VerboseForegroundColor = $Host.UI.RawUI.ForegroundColor
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], SetValueInvocationException
+ FullyQualifiedErrorId : ExceptionWhenSetting
You cannot call a method on a null-valued expression.
At C:\Scripts\PsFCIV_2.5.ps1:612 char:4
+ $sum.FILE_ENTRY.Add($entry)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Exception setting "VerboseForegroundColor": "Cannot convert value "-1" to type "System.Windows.Media.Color". Error: "Invalid cast from 'System.ConsoleColor' to 'System.Windows.Media.Color'.""
At C:\Scripts\PsFCIV_2.5.ps1:607 char:4
+ $host.PrivateData.VerboseForegroundColor = $Host.UI.RawUI.ForegroundColor
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], SetValueInvocationException
+ FullyQualifiedErrorId : ExceptionWhenSetting
How can I get this command to work? I could not find any solutions or similar problems after ~15 min search.
The first exception you get is thrown by Set-Location cmdlet that for some reason is used in the Start-PsFCIV script. Set-Location expects a folder as its -LiteralPath argument but you pass it a file instead.
As per "Useful Examples" on the PsFCIV webpage the solution is to use -Include argument. Example:
Start-PsFCIV -Path C:\tmp -Include InstallPackage.msi -XML DB.XML -HashAlgorithm SHA512
# Checks only InstallPackage.msi file in C:\tmp folder by using SHA512 hash algorithm.

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)