*** Please fill in the fields below. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***
Product, version and build: Powershell Studio 2019 5.6.167
32 or 64 bit version of product: 64-bit
Operating system: Windows 10 1803
32 or 64 bit OS: 64-bit
*** Please add details and screenshots as needed below. ***
Hello, i have an issue with Powershell studio saving a form it cuts off some code attached to a button. The script itself works without a problem.
- # Details of the runbook we are going to run
- $rbid = "abf850c5-24ba-4d2f-84fb-5eefee0bcab8"
- $rbParameters = @{ "a04171a9-5f99-48da-b0ce-4c62cd7c6029" = "$Global:var_computer"; "3ca59135-5ebe-4e76-a4a5-920b5bf259ba" = $Global:var_ticket; "3840ea3d-5725-45ff-83a7-4cab2b154de8" = $Global:var_user }
- # Create the request object
- $request = [System.Net.HttpWebRequest]::Create("http://******:81/Orchestrator2012/Orchestrator.svc/Jobs")
- # Set the credentials to default or prompt for credentials
- $request.UseDefaultCredentials = $true
- #$request.Credentials = Get-Credential
- # Build the request header
- $request.Method = "POST"
- $request.UserAgent = "Microsoft ADO.NET Data Services"
- $request.Accept = "application/atom+xml,application/xml"
- $request.ContentType = "application/atom+xml"
- $request.KeepAlive = $true
- $request.Headers.Add("Accept-Encoding", "identity")
- $request.Headers.Add("Accept-Language", "en-US")
- $request.Headers.Add("DataServiceVersion", "1.0;NetFx")
- $request.Headers.Add("MaxDataServiceVersion", "2.0;NetFx")
- $request.Headers.Add("Pragma", "no-cache")
- # If runbook servers are specified, format the string
- $rbServerString = ""
- if (-not [string]::IsNullOrEmpty($RunbookServers))
- {
- $rbServerString = -join ("<d:RunbookServers>", $RunbookServers, "</d:RunbookServers>")
- }
- # Format the Runbook parameters, if any
- $rbParamString = ""
- if ($rbParameters -ne $null)
- {
- # Format the param string from the Parameters hashtable
- $rbParamString = "<d:Parameters><![CDATA[<Data>"
- foreach ($p in $rbParameters.GetEnumerator())
- {
- #$rbParamString = -join ($rbParamString,"<Parameter><ID>{",$p.key,"}</ID><Value>",$p.value,"</Value></Parameter>")
- $rbParamString = -join ($rbParamString, "<Parameter><ID>{", $p.key, "}</ID><Value>", $p.value, "</Value></Parameter>")
- }
- $rbParamString += "</Data>]]></d:Parameters>"
- }
- # Build the request body
- $requestBody = @"
- <?xml version="1.0" encoding="utf-8" standalone="yes"?>
- <entry xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
- <content type="application/xml">
- <m:properties>
- <d:RunbookId m:type="Edm.Guid">$rbid</d:RunbookId>
- $rbserverstring
- $rbparamstring
- </m:properties>
- </content>
- </entry>
- "@
- # Create a request stream from the request
- $requestStream = new-object System.IO.StreamWriter $Request.GetRequestStream()
- # Sends the request to the service
- $requestStream.Write($RequestBody)
- $requestStream.Flush()
- $requestStream.Close()
- # Get the response from the request
- [System.Net.HttpWebResponse]$response = [System.Net.HttpWebResponse]$Request.GetResponse()
- # Write the HttpWebResponse to String
- $responseStream = $Response.GetResponseStream()
- $readStream = new-object System.IO.StreamReader $responseStream
- $responseString = $readStream.ReadToEnd()
- # Close the streams
- $readStream.Close()
- $responseStream.Close()
- # Get the ID of the resulting job
- if ($response.StatusCode -eq 'Created')
- {
- $xmlDoc = [xml]$responseString
- $jobId = $xmlDoc.entry.content.properties.Id.InnerText
- Write-Host "Successfully started runbook. Job ID: " $jobId
- }
- else
- {
- Write-Host "Could not start runbook. Status: " $response.StatusCode
- }
The problem happens when i link the above code to a button, launching the form works until i save it. Once saved and opened again Powershell studio decides to remove part of the code. When i load the project again this is what remains from the above script:
- $rbid = "7810ee58-6970-4f74-b00c-4f107f638608"
- $rbParameters = @{ "161a1de9-712b-457e-adec-47840fb86dc0" = "$Global:var_computer"; "b183de03-3248-49e1-bfa8-d1cfd0727d12" = "$Global:var_ticket" }
- # Create the request object
- $request = [System.Net.HttpWebRequest]::Create("*******:81/Orchestrator2012/Orchestrator.svc/Jobs")
- # Set the credentials to default or prompt for credentials
- $request.UseDefaultCredentials = $true
- #$request.Credentials = Get-Credential
- # Build the request header
- $request.Method = "POST"
- $request.UserAgent = "Microsoft ADO.NET Data Services"
- $request.Accept = "a[Codebox=powershell file=Untitled.ps1]pplication/atom+xml,application/xml"
- $request.ContentType = "application/atom+xml"
- $request.KeepAlive = $true
- $request.Headers.Add("Accept-Encoding", "identity")
- $request.Headers.Add("Accept-Language", "en-US")
- $request.Headers.Add("DataServiceVersion", "1.0;NetFx")
- $request.Headers.Add("MaxDataServiceVersion", "2.0;NetFx")
- $request.Headers.Add("Pragma", "no-cache")
- # If runbook servers are specified, format the string
- $rbServerString = ""
- if (-not [string]::IsNullOrEmpty($RunbookServers))
- {
- $rbServerString = -join ("<d:RunbookServers>", $RunbookServers, "</d:RunbookServers>")
- }
- # Format the Runbook parameters, if any
- $rbParamString = ""
- if ($rbParameters -ne $null)
- {
- # Format the param string from the Parameters hashtable
- $rbParamString = "<d:Parameters><![CDATA[<Data>"
- foreach ($p in $rbParameters.GetEnumerator())
- {
- #$rbParamString = -join ($rbParamString,"<Parameter><ID>{",$p.key,"}</ID><Value>",$p.value,"</Value></Parameter>")
- $rbParamString = -join ($rbParamString, "<Parameter><ID>{", $p.key, "}</ID><Value>", $p.value, "</Value></Parameter>")
- }
- $rbParamString += "</Data>]]
When i save it as a script (ps1) it leaves the code as it is after loading it again.
Any idea what could be causing this?