I want to add web part in web part zone using powershell script - sharepoint

I want to add web part in the web part zone programmatically only using power shell script
I am getting this exception using power shell scripting
Exception code
$webPart = $webpartmanager.ImportWebPart($xmlReader, $errorMsg) -as [Microsoft.SharePoint.WebPartPages.WebPart]
Argument: '2' should be a System.Management.Automation.PSReference. Use [ref].
+ $webPart = $webpartmanager.ImportWebPart <<<< ($xmlReader, $errorMsg) -as [Microsoft.SharePoint.WebPartPages.WebPart]
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : NonRefArgumentToRefParameterMsg

Have you tried what the error message suggests (note the addition of [ref] before $errorMsg)?
$webPart = $webpartmanager.ImportWebPart($xmlReader, [ref]$errorMsg)
-as [Microsoft.SharePoint.WebPartPages.WebPart]

Related

Oh My Posh seems to randomly throw an exception and does not load the cli

For some reason, OMP will throw this error, seemingly randomly, and will not load the input line.
It happens in VSC and VSCodium, as far as I have noticed.
Restarting the programs or opening a new terminal does not help, it just shows the error below again and again.
If I leave the console open it also spams a new line infinitely. SMH...
Then, suddenly, as randomly as it seems to happen, everything works again.
Usually after a few minutes, which is pretty annoying if I need the terminal right there and then.
I am using a custom local config for OMP.
Any advice about what to even check would be appreciated.
Set-PSReadLineOption : The type initializer for 'Microsoft.PowerShell.PSConsoleReadLine' threw an exception.
At line:381 char:5
+ Set-PSReadLineOption -ContinuationPrompt (#(Start-Utf8Process $sc ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Set-PSReadLineOption], TypeInitializationException
+ FullyQualifiedErrorId : System.TypeInitializationException,Microsoft.PowerShell.SetPSReadLineOption

I get this error when I run a .py file in vs code, it says something is not recognized , can anyone help me to fix that?

I get this error when I run a .py file in vs code:
n38-32" "c:/Users/hassan kh/Desktop/MY FOLDER/Python Projects/1_1.py"
& : The term 'C:/Users/hassan kh/AppData/Local/Programs/Python/Python38-32' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or
if a path was included, verify that the path is correct and try again.
At line:1 char:3
+ & "C:/Users/hassan kh/AppData/Local/Programs/Python/Python38-32" "c:/Users/hassa ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:/Users/hassan...hon/Python38-32:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
I deleted Python and vs code and installed it again but I get this error yet. if anyone knows or had this problem before, please let me know how can I fix it?
Isn't the path should be with backward slash \ in the path.

"Upload of file '...' was successful, but error occurred while setting the permissions and/or timestamp" when using WinSCP .NET assembly in PowerShell

Exception calling "Check" with "0" argument(s): "Upload of file '2019-06-11.zip'
was successful, but error occurred while setting the permissions and/or
timestamp.
If the problem persists, turn off setting permissions or preserving timestamp.
Alternatively you can turn on 'Ignore permission errors' option.
Permission denied.
Error code: 3
Error message from server: This server does not support operations to modify
file attributes."
At line:12 char:84
+ $session.PutFiles("D:\Users\bin\*.zip", "/Outbox/").Check <<<< ()
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
I keep on getting above error file transferring file from Window Server to Linux. I got the same error when using the WinSCP GUI as well. I asked MFT team and they didn't any set permission. Below are my script for file transferring and some of intro version of software I'm using. Anything I missed out for my script or version of software is too old? I will have an update of server soon but have to wait another 2 yrs. This task will be set as scheduler to transfer file daily to MFT server.
Version of software:
Use .NET 4.0
Use PowerShell v2.0
Window Server 2008
Placed private.ppk, WinSCPNet.dll and WinSCP.exe at same folder
#Load WinSCP .NET assembly
Add-Type -Path "D:\Users\WinSCPnet.dll" -Verbose
$session = New-Object WinSCP.Session
$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
$sessionOptions.HostName = "[Linux server IP]"
$sessionOptions.UserName = "[username]"
$sessionOptions.PortNumber = "[linux port number]"
$sessionOptions.Password = ""
$sessionOptions.SshPrivateKeyPath = "D:\Users\bin.ppk"
$sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2048 ....="
try {
# Open the WinSCP.Session object using the WinSCP.SessionOptions object.
$session.Open($sessionOptions)
# Upload
$session.PutFiles("D:\Users\bin\*.zip", "/Outbox/").Check()
} finally {
# Disconnect, clean up
$session.Dispose()
}
The error is documented here:
https://winscp.net/eng/docs/message_preserve_time_perm
Your server does not support updating timestamps of uploaded remote files. So you need to instruct WinSCP not to attempt it:
$transferOptions = New-Object WinSCP.TransferOptions
...
$transferOptions.PreserveTimestamp = $False
$session.PutFiles("D:\Users\bin\*.zip", "/Outbox/", $False, $transferOptions).Check()

A parameter cannot be found that matches parameter name 'MaxSizeGB'

New-AzureSqlDatabase command on execution suddently started failing with parameter not found message. MSDN link mentions the parameter as supported.
https://msdn.microsoft.com/en-us/library/dn546722.aspx
Command : New-AzureSqlDatabase
Input
PS C:\scripts>$database1 = New-AzureSqlDatabase -ServerName
"lpqd0zbrseg" -DatabaseName "Database1" -Edition "Business" -MaxSizeGB
50 -Collation "SQL_Latin1_General_CP1_CI_AS"
Output Error
New-AzureSqlDatabase : A parameter cannot be found that matches
parameter name 'MaxSizeGB'. At line:1 char:103
+ ... dition "Basic" -MaxSizeGB 1 -Collation "SQL_Latin1_General_CP1_CI_AS"
+ ~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-AzureSqlDatabase], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.Azure.Commands.Sql.Database.Cmdlet.NewAzureSqlDatabas
What would be the reason that MaxSizeGB parameter got not found on execution. Thanks in advance
With Regards,
H Bala
Business and Wed editions are a deprecated service level. Now, the service levels are Free, Basic, Standard & Premium as the error shows.
About the parameter, are you using the Azure PowerShell module configured as "Resource Manager" or "Service Management"? The first one hasn't that value but the second one have it.
You can change it with "Switch-AzureMode". You can find the explanation in the second section of the page.
Source Code of Resource Manager command
Source Code of Service Management command

Powershell and System.Security.Cryptography.X509Certificates.X509Certificate2

i'm getting this error when i run the system.security namespace. This is what i am running after
$cert=New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("C:\mycert.cer")
New-Object: Cannot find type [System.Security.Cryptography.X509Certificates.X509Certificate2("C:\mycert.cer")]: make sure the assembly containing this type is loaded.
At line:1 char:19
+ $cert = New-Object <<<<
+ CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
+ FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand**
What am i doing wrong?
Try running this to see if you have the System.dll loaded (should be by default):
[AppDomain]::CurrentDomain.GetAssemblies() |
Where {$_.Location -match '\\System\\'}
If it is loaded then this command should show the X509Certificate2 type:
[AppDomain]::CurrentDomain.GetAssemblies() |
Where {$_.Location -match '\\System\\'} |
%{$_.GetExportedTypes()} | Where {$_.Name -match 'X509Cert'}
If the System.dll isn't loaded (which would be odd) try loading it:
Add-Type -AssemblyName System
See: http://technet.microsoft.com/en-us/library/hh849914.aspx
FYI ... I got error:
Unable to find type [System.Security.Cryptography.x509Certificates.X509Certificate2UI]
when using:
$certSelect = [System.Security.Cryptography.x509Certificates.X509Certificate2UI]::SelectFromCollection($certCollection, $title, $msg, 0)
However, I had no error creating the collection earlier on in my script:
$certCollection = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2Collection
To make the error go away I had to include the following at some point earlier on:
Add-Type -AssemblyName System.Security
I've solved my problem. It's easily:
cd\
$cert=New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("C:\mycert.cer")
cd\ is necessary
I ran into this in the ISE (but seems to apply to the normal command window too) and it seems that using autocomplete will automatically Add-Type for whatever you're looking for. If you start a new instance and run:
[AppDomain]::CurrentDomain.GetAssemblies() | grep Security
it will not return System.Security, but if you then type this and let intellisense do its thing:
[System.
You can then run this again:
[AppDomain]::CurrentDomain.GetAssemblies() | grep Security
And it will then return System.Security. So this is why you can write a script that works fine, and then revisit it later and it's broken. Using intellisense doesn't fix your script though, instead you have to add this line:
Add-Type System.Security
Or whatever library is not getting auto-added (it seems to need the dll filename, e.g. C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Security.dll).
I'm pretty sure IseSteroids (a paid ISE add-in) can detect this, maybe others as well.

Resources