I have a PowerShell script in one of the GCS buckets. I configured a GCE instance to use this as the startup script. This GCE instance has service accounts and has the necessary API access. However, when the script starts running, I see parsing errors. I can run the script locally without any issues. This happens only when I use that from a GCS bucket. If I put the script as a Github gist, it runs perfectly as well.
Here is what I see in the serial console log.
2018/02/27 18:08:25 GCEMetadataScripts: Starting startup scripts (version 4.1.6#1).
2018/02/27 18:08:42 GCEMetadataScripts: Found windows-startup-script-url in metadata.
2018/02/27 18:10:09 windows-startup-script-url: At C:\Windows\TEMP\metadata-scripts968189735\windows-startup-script-url.ps1:2
2018/02/27 18:10:09 windows-startup-script-url: char:9
2018/02/27 18:10:09 windows-startup-script-url: + "error": {
2018/02/27 18:10:09 windows-startup-script-url: + ~
2018/02/27 18:10:09 windows-startup-script-url: Unexpected token ':' in expression or statement.
2018/02/27 18:10:09 windows-startup-script-url: At C:\Windows\TEMP\metadata-scripts968189735\windows-startup-script-url.ps1:3
2018/02/27 18:10:09 windows-startup-script-url: char:11
2018/02/27 18:10:09 windows-startup-script-url: + "errors": [
2018/02/27 18:10:09 windows-startup-script-url: + ~
2018/02/27 18:10:09 windows-startup-script-url: Unexpected token ':' in expression or statement.
2018/02/27 18:10:09 windows-startup-script-url: At C:\Windows\TEMP\metadata-scripts968189735\windows-startup-script-url.ps1:5
2018/02/27 18:10:09 windows-startup-script-url: char:13
2018/02/27 18:10:09 windows-startup-script-url: + "domain": "global",
2018/02/27 18:10:09 windows-startup-script-url: + ~
2018/02/27 18:10:09 windows-startup-script-url: Unexpected token ':' in expression or statement.
2018/02/27 18:10:09 windows-startup-script-url: At C:\Windows\TEMP\metadata-scripts968189735\windows-startup-script-url.ps1:11
2018/02/27 18:10:10 windows-startup-script-url: char:4
2018/02/27 18:10:10 windows-startup-script-url: + ],
2018/02/27 18:10:10 windows-startup-script-url: + ~
2018/02/27 18:10:10 windows-startup-script-url: Missing argument in parameter list.
2018/02/27 18:10:10 windows-startup-script-url: + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordEx
2018/02/27 18:10:10 windows-startup-script-url: ception
2018/02/27 18:10:10 windows-startup-script-url: + FullyQualifiedErrorId : UnexpectedToken
2018/02/27 18:10:10 windows-startup-script-url:
2018/02/27 18:10:10 GCEMetadataScripts: windows-startup-script-url exit status 1
2018/02/27 18:10:10 GCEMetadataScripts: Finished running startup scripts.
Here is the startup script.
[DscLocalConfigurationManager()]
Configuration GCEDscMetaConfig
{
param
(
[Parameter(Mandatory = $true)]
[String]
$RegistrationUrl,
[Parameter(Mandatory = $True)]
[String]
$RegistrationKey,
[Parameter(Mandatory = $true)]
[String[]]
$ConfigurationNames
)
Node localhost
{
Settings
{
RefreshMode = 'Pull'
}
ConfigurationRepositoryWeb AzureAutomationDSC
{
ServerUrl = $RegistrationUrl
RegistrationKey = $RegistrationKey
ConfigurationNames = $ConfigurationNames
}
ResourceRepositoryWeb AzureAutomationDSC
{
ServerUrl = $RegistrationUrl
RegistrationKey = $RegistrationKey
}
ReportServerWeb AzureAutomationDSC
{
ServerUrl = $RegistrationUrl
RegistrationKey = $RegistrationKey
}
}
}
$Params = #{
RegistrationUrl = 'https://pullserver/accounts/7471b7ce-95d2-4766-be97-221f4d33f56a'
RegistrationKey = 'ljey=='
ConfigurationNames = 'webserver.localhost'
OutputPath = "$env:TEMP\MetaConfig"
}
GCEDscMetaConfig #Params
Set-DscLocalConfigurationManager -Path "$env:TEMP\MetaConfig" -Verbose
This is just a DSC meta configuration script.
Any idea what I am missing here?
Related
Error being received when trying to connect:
New-ExoPSSession : One or more errors occurred.
At C:\Program Files\WindowsPowerShell\Modules\ExchangeOnlineManagement\2.0.5\netFramework\ExchangeOnlineManagement.psm1:475 char:30
+ ... PSSession = New-ExoPSSession -ExchangeEnvironmentName $ExchangeEnviro ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-ExoPSSession], AggregateException
+ FullyQualifiedErrorId : System.AggregateException,Microsoft.Exchange.Management.ExoPowershellSnapin.NewExoPSSession
I'm getting following error while running the powershell solution checker script for CI:
Get-PowerAppsCheckerRulesets : An error occurred while sending the request.
At C:\MSDynamics\BuildScripts\PowerShell\SolutionCheckerCI.ps1:31 char:13
+ $rulesets = Get-PowerAppsCheckerRulesets -Geography Europe -TenantId ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-PowerAppsCheckerRulesets], HttpRequestException
+ FullyQualifiedErrorId : System.Net.Http.HttpRequestException,Microsoft.PowerApps.Checker.PowerShell.Cmdlets.GetPowerAppsCheckerRulesets
I need to create a button on a PowerShell GUI to save the content of a DataGridView when pressed. This needs to open a file dialogue box to select the destination and give it a file name.
See code for what I have already tried
$btnSave_Click={
$saveFile = New-Object System.Windows.Forms.SaveFileDialog
$saveFile.Filter = "Comma Delimited (*.csv) | *.csv "
$saveFile.FileName
if ($saveFile.ShowDialog() -eq 'OK')
{
$results.SelectAll()
$results.ClipboardCopyMode = 'EnableAlwaysIncludeHeaderText'
$results.GetClipboardContent().GetData('Text') | Out-File
$saveFile.FileName
}
}
Error received is
ERROR: You cannot call a method on a null-valued expression.
ERROR: char:4
ERROR: + $results.SelectAll()
ERROR: + ~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR: + CategoryInfo : InvalidOperation: (:) [],
RuntimeException
ERROR: + FullyQualifiedErrorId : InvokeMethodOnNull
ERROR:
ERROR: The property 'ClipboardCopyMode' cannot be found on this object.
Verify that the property exists and can be set.
ERROR: char:4
ERROR: + $results.ClipboardCopyMode
= 'EnableAlwaysIncludeHea ...
ERROR: +
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR: + CategoryInfo : InvalidOperation: (:) [],
RuntimeException
ERROR: + FullyQualifiedErrorId : PropertyNotFound
ERROR:
ERROR: You cannot call a method on a null-valued expression.
ERROR: char:4
ERROR: + $results.GetClipboardContent().GetData('Text') |
Out ...
ERROR: +
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR: + CategoryInfo : InvalidOperation: (:) [],
RuntimeException
ERROR: + FullyQualifiedErrorId : InvokeMethodOnNull
ERROR:
maybe you meant
$result = $DataGridViewdata.selectall()
I was confronted with the following error:
Add-Type : Die Datei oder Assembly "file://\\myuncpath\my.dll" oder eine Abhängigkeit
davon wurde nicht gefunden. Der Vorgang wird nicht unterstützt. (Ausnahme von HRESULT: 0x80131515)
In Zeile:1 Zeichen:1
+ Add-Type -Path "\\myuncpath\my.dll"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Add-Type], FileLoadException
+ FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell.Commands.AddTypeCommand
Sorry for it being German but I guess sole the stack trace will help out as well.
And fixed it by enabling loadFromRemoteSources. However this just fixes it for the Powershell ISE not for the typical command prompt that starts when I use right click -> "execute Powershell script".
Does the config not apply to the normal prompt?
Error in English:
Add-Type : Could not load file or assembly 'file://\\myuncpath\my.dl'
or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
At line:1 char:1 + Add-Type -Path "\\myuncpath\my.dll"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Add-Type], FileLoadException
+ FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell.Commands.AddTypeCommand
Whenever I open the package manager console in new VS 2017 session, it shows the below two error messages, and the for all intents and purposes operates normally. At least for vanilla commands like Install-Package.
Join-Path : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'ChildPath'. Specified method is not supported.
At C:\Dev\.NET\Projects\AcmeSoft\Code\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\tools\init.ps1:13 char:57
+ ... rPackageDirectory = Join-Path $packageDirectory $compilerPackage.Name
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Join-Path], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.JoinPathCommand
and
Join-Path : Cannot bind argument to parameter 'Path' because it is null.
At C:\Dev\.NET\Projects\AcmeSoft\Code\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\tools\init.ps1:14 char:44
+ ... erPackageToolsDirectory = Join-Path $compilerPackageDirectory 'tools'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Join-Path], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.JoinPathCommand
The offending line for the first is:
$compilerPackageDirectory = Join-Path $packageDirectory $compilerPackage.Name
with the error at $compilerPackage.Name (i.e. "char:57")
The offending line for the second is:
$compilerPackageToolsDirectory = Join-Path $compilerPackageDirectory 'tools'
with the error at $compilerPackageDirectory 'tools'.
Can anyone with more Nuget and or PowerShell skills than me explain why this is happening, and how I can fix it, please?