Hello
I have problem about script which runs on Sharepoint environment. When i just run the cmdlet itself, (merge-splogfile) creating a file and its visible on desktop. When i run whole script via PowerShell Studio through button, process is stucking at about %90 percent and not completing itself.
Other buttons are working fine
$path and $correlation values are okay but script is not finishing.
Any idea?
attachment added.
SharePoint Commands Run itself bu Not with Powershell Studio
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
SharePoint Commands Run itself bu Not with Powershell Studio
- Attachments
-
- correlation.Export.ps1
- (7.85 KiB) Downloaded 74 times
Last edited by mikarin on Sat Jan 25, 2020 7:32 am, edited 1 time in total.
Re: SharePoint Commands Run itself bu Not with Powershell Studio
Please add the PSF file as an attachment. You have added the exported PS1 file. The PSF file is easier to load and gives more information.
- Alexander Riedel
- Posts: 8488
- Last visit: Tue Apr 16, 2024 8:42 am
- Been upvoted: 37 times
Re: SharePoint Commands Run itself bu Not with Powershell Studio
Permissions or threading are the usual suspects. Try running it with STA. Does it require elevation? When you run the script from PowerShell Studio, it will not execute any profile.
So if your profile has specific presets you should transfer those to your script. This way you never create local dependencies.
So if your profile has specific presets you should transfer those to your script. This way you never create local dependencies.
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: SharePoint Commands Run itself bu Not with Powershell Studio
I do not believe this is due to the threading model as the code itself is not written correctly and the log is being generated for all log entries due to the code design error.
The reason I asked for the PSF is so I could give the attached as an answer:
Unfortunately the site no longer allows us to upload files. Something seems to have disabled that capability.
The issue is one of scoping. I also showed the better method for including the VB assembly and using it. Ideally we would want to use a textbox on the form for the input.
Here is the changed code. Add a textbox as named to save the value.
The reason I asked for the PSF is so I could give the attached as an answer:
Unfortunately the site no longer allows us to upload files. Something seems to have disabled that capability.
The issue is one of scoping. I also showed the better method for including the VB assembly and using it. Ideally we would want to use a textbox on the form for the input.
Here is the changed code. Add a textbox as named to save the value.
Code: Select all
$path = [void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
$form1_Load={
}
$buttonFilename_Click={
$text = [Microsoft.VisualBasic.Interaction]::InputBox('Enter the File Name:', 'Path')
}
$buttonCorrelationID_Click={
$textboxCorrelationID.Text = [Microsoft.VisualBasic.Interaction]::InputBox('Correlation', 'Enter the CorrelationID:')
}
$buttonMerge_Click={
$result= Merge-SpLogFile -path C:\Users\$env:USERNAME\Desktop\$text.txt -Correlation $textboxCorrelationID.Text
}
$button1_Click={
Invoke-Item -path C:\Users\$env:USERNAME\Desktop\$text.txt
}
Re: SharePoint Commands Run itself bu Not with Powershell Studio
Nope - wrong. The editor is not available under Edge (Chrome version) but is with IE.
Here is the PSF.
Edge has the "options" tab but no "attachments" tab. Strange.
Here is the PSF.
Edge has the "options" tab but no "attachments" tab. Strange.
- Attachments
-
- correlation.psf
- (31.63 KiB) Downloaded 87 times
Re: SharePoint Commands Run itself bu Not with Powershell Studio
To be more specific, when using variables in events the variables are locally scoped to the event and not visible in other events or outside of the event. The best way to access values is to use controls as the controls are scoped to the script and available anywhere inside the form and all events.
Another approach is to declare the variables as "script" scope and then it will be available in events.
This will then be available in the event that needs the variable. Accessing the variable can be done with or without the scope modifier but the scope modifier must be used anywhere the variable is assigned.
You can also pre-define the variable outside of any event code and it will be scoped at the script scope but assignments will still always require the scope modifier.
Another approach is to declare the variables as "script" scope and then it will be available in events.
Code: Select all
$buttonCorrelationID_Click={
$script:text = [Microsoft.VisualBasic.Interaction]::InputBox('Correlation', 'Enter the CorrelationID:')
}
You can also pre-define the variable outside of any event code and it will be scoped at the script scope but assignments will still always require the scope modifier.
Re: SharePoint Commands Run itself bu Not with Powershell Studio
PS> If the issue was threading I believe we should get an exception and the event would complete. It might depend on which version of the server support module is installed. For 2016 and later it should just run until all log entries are merged which can take a very long time on large servers. I am surprised that a null CorrelationID causes this behavior. I would have thought it would cause an error.
The event code looks like this:
The following PSF version demonstrates both methods and shows how to correctly incorporate the variables into the strings.
The event code looks like this:
Code: Select all
Add-Type -AssemblyName Microsoft.VisualBasic
$buttonFilename_Click={
$script:filename = [Microsoft.VisualBasic.Interaction]::InputBox('Enter the File Name:', 'Path')
}
$buttonCorrelationID_Click={
$textboxCorrelationID = [Microsoft.VisualBasic.Interaction]::InputBox('Correlation', 'Enter the CorrelationID:')
}
$buttonMerge_Click={
$result= Merge-SpLogFile -path "C:\Users\$env:USERNAME\Desktop\$filename.txt" -Correlation $textboxCorrelationID.Text
}
$button1_Click={
Invoke-Item "C:\Users\$env:USERNAME\Desktop\$filename.txt"
}
- Attachments
-
- correlation2.psf
- (31.63 KiB) Downloaded 93 times
Re: SharePoint Commands Run itself bu Not with Powershell Studio
So in which part of the script i should assign variables which can be accessible outside of script bloks?