My project is to write a script with an XAML form that will display in PowerShell.
I have two script files. FirstScript.ps1 which has the following code:
# Required to load the XAML form and create the Powershell Variables
.\LoadDialog.ps1 -XamlPath '.\ADMgmtForm.xaml'
Write-Output "Hello, World!"
Write-Output ""
My second script file LoadDialogue.ps1 has the following code:
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True,Position=1)]
[string]$XamlPath
)
[xml]$Global:xmlWPF = Get-Content -Path $XamlPath
# Add WPF and Windows Forms assemblies
try{
Add-Type -AssemblyName PresentationCore, PresentationFramework, WindowsBase,
system.windows.forms
} catch {
Throw "Failed to load Windows Presentation Framework assemblies."
}
# Create the XAML reader using a new XML node reader
$Global:xamGUI = [Windows.Markup.XamlReader]::Load((new-object
System.Xml.XmlNodeReader $xmlWPF))
# Create hooks to each named object in the XAML
$xmlWPF.SelectNodes("//*[#Name]") | %{
Set-Variable -Name ($_.Name) -Value $xamGUI.FindName($_.Name) -Scope Global
}
My Form file has the following code:
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid Margin="0,0,61,0">
<Label Name="Label1" Content="Label" HorizontalAlignment="Left"
Margin="68,38,0,0" VerticalAlignment="Top" Width="197"/>
<Button Name="DispGrps" Content="Button" HorizontalAlignment="Left"
Margin="49,251,0,0" VerticalAlignment="Top" Width="124" Height="41"
FontWeight="Bold"/>
<Button Name="SelectGrps" Content="Button" HorizontalAlignment="Left"
Margin="301,251,0,0" VerticalAlignment="Top" Width="106" Height="41"
FontWeight="Bold"/>
</Grid>
</Window>
When I call FirstScript.ps1 in PowerShell I see the output of "Hello World", but I also get this error message:
PS C:\Users\myusernamehere\Desktop\ADMgmtProject\Scripts> .\FirstScript.ps1
.\LoadDialog.ps1 : The term '.\LoadDialog.ps1' 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 C:\Users\myusernamehere\Desktop\ADMgmtProject\Scripts\FirstScript.ps1:2
char:1
+ .\LoadDialog.ps1 -XamlPath '.\ADMgmtForm.xaml'
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (.\LoadDialog.ps1:String) [],
CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Hello, World!
I have tried initializing . .\FirstScript.ps1 and I get the same error message. I have tried adding &"" before LoadDialogue in my LoadDialogue.ps1 script.
Can anyone help?
Related
I am trying to build a UWP app from the command-line in an effort to automate the builds from check-in to publishing to the store. Everything works fine when running the builds from within Visual Studio and when I create app packages, it all works fine (but takes too long, 15 minutes or so).
While invoking msbuild per platform (x86, x64 & ARM), only ARM seems to fail with the following error:
_CreatePriConfigXmlForSplitting
"C:\Source\MyProject\src\MyProject\MyProject.csproj" (Build target) (1) ->
(_SplitResourcesPri target) ->
error PRI175 : 0x80070002 - Processing Resources failed with error : The system cannot find the file specified. [C:\Source\MyProject\src\MyProject\MyProject.csproj]
GENERATEPROJECTPRIFILE : error PRI252: 0xdef00071 - File C:\Source\MyProject\output\Release\x86\arm\MyProject\resources.pri not found. [C:\Source\MyProject\src\MyProject\MyProject.csproj]
0 Warning(s)
2 Error(s)
As you probably noticed, it's using x86\arm directory instead of arm, hence the build is failing.
I am using Cake to build this, below is (relevant part of) the script:
Task("Build")
.IsDependentOn("Clean")
.IsDependentOn("UpdateVersion")
.IsDependentOn("RestorePackages")
.Does(() =>
{
var platforms = new Dictionary<string, PlatformTarget>();
platforms["ARM"] = PlatformTarget.ARM;
platforms["x86"] = PlatformTarget.x86;
platforms["x64"] = PlatformTarget.x64;
foreach (var platform in platforms)
{
Information("Building project for platform {0}", platform.Key);
var outputDirectory = "../../" + outputRootDirectory + "/" + platform.Value.ToString();
var projectFileName = string.Format("./src/{0}/{0}.csproj", solutionName);
var msBuildSettings = new MSBuildSettings {
Verbosity = Verbosity.Diagnostic, // Verbosity.Minimal
ToolVersion = MSBuildToolVersion.VS2017,
Configuration = configurationName,
MSBuildPlatform = MSBuildPlatform.x86, // Always require x86, see platform for actual target platform
PlatformTarget = platform.Value
};
// Need special path since this is relative to the project file, not the cake build directory
//msBuildSettings.Properties["OutputPath"] = new List<string>(new [] { outputDirectory });
// We don't create native builds, we will use MSIL builds which the store will recompile,
// for more info see https://oren.codes/2015/12/03/continuous-integration-for-uwp-projects-making-builds-faster/
msBuildSettings.Properties["UseDotNetNativeToolchain"] = new List<string>(new [] { "false" });
msBuildSettings.Properties["BuildAppxUploadPackageForUap"] = new List<string>(new [] { "true" });
//msBuildSettings.Properties["AppxPackageArtifactsDir"] = new List<string>(new [] { outputDirectory });
// Fix for broken targets
//msBuildSettings.Properties["ProjectPriFileName"] = new List<string>(new [] { "resources.pri" });
//msBuildSettings.Properties["ProjectPriFullPath"] = new List<string>(new [] { outputDirectory + "/resources.pri" });
//msBuildSettings.Properties["_TransformedProjectPriFullPath"] = new List<string>(new [] { outputDirectory + "/resources.pri" });
MSBuild(projectFileName, msBuildSettings);
}
});
A. As you can see I am experimenting a bit by manually overriding the ms build properties, but no luck so far.
B. At first I thought it was GenerateProjectPriFile task that was failing. However, after some investigation I found out that creating the split files already show use the wrong startIndexAt value:
<?xml version="1.0" encoding="utf-8"?>
<resources targetOsVersion="10.0.0" majorVersion="1">
<packaging>
<autoResourcePackage qualifier="Language" />
<autoResourcePackage qualifier="Scale" />
<autoResourcePackage qualifier="DXFeatureLevel" />
<omitSchemaFromResourcePacks />
</packaging>
<index root="\" startIndexAt="C:\Source\MyProject\output\Release\x86\arm\MyProject\resources.pri">
<default>
<qualifier name="Language" value="en-US" />
<qualifier name="Contrast" value="standard" />
<qualifier name="Scale" value="200" />
<qualifier name="HomeRegion" value="001" />
<qualifier name="TargetSize" value="256" />
<qualifier name="LayoutDirection" value="LTR" />
<qualifier name="DXFeatureLevel" value="DX9" />
<qualifier name="Configuration" value="" />
<qualifier name="AlternateForm" value="" />
<qualifier name="Platform" value="UAP" />
</default>
<indexer-config type="PRI" />
</index>
</resources>
I have no idea why it prepends x86 before ARM when building for ARM. Any help is appreciated. In the meantime I'll continue investigating and update this post if I find something new.
It looks like I have to specify the sln file, not the csproj file. This is a bit unfortunate since now it builds much more than it needs to (there are multiple projects in the same solution), but I can get around that by creating a custom MyProject.Build.sln file
I am trying to upload files using laravel5.1.But i am facing error like
FatalErrorException in Handler.php line 25:
Uncaught TypeError: Argument 1 passed to App\Exceptions\Handler::report() must be an instance of Exception, instance of Error given, called in E:\xampp\htdocs\mp-admin\vendor\compiled.php on line 1720 and defined in E:\xampp\htdocs\mp-admin\app\Exceptions\Handler.php:25
Stack trace:
#0 E:\xampp\htdocs\mp-admin\vendor\compiled.php(1720): App\Exceptions\Handler->report(Object(Error))
#1 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleException(Object(Error))
#2 {main}
thrown
Here is my view
<div class="form-group">
<label >Logo</label>
<input type="file" name="image" >
</div>
Controller:
$entry = new companyprofiles();
$file = Input::get('image');
$extension = $file->getClientOriginalExtension();
Storage::disk('local')->put($file->getFilename().'.'.$extension, File::get($file));
$entry->mime = $file->getClientMimeType();
$entry->original_filename = $file->getClientOriginalName();
$entry->filename = $file->getFilename().'.'.$extension;
$entry->save();
But first when i was trying it was storing in database and folder as well.after that continuously giving the same above error.
Please help me with this.if i do dd the value also its giving me the same error i could not able to find where is the error.Not getting stored in database.
Remove or delete vendor/compile.php
Run composer dump-autoload
if not work then
run composer update
I am trying to follow this article to expand a variable in a scriptblock
My code tries this:
$exe = "setup.exe"
invoke-command -ComputerName $j -Credential $credentials -ScriptBlock {cmd /c 'C:\share\[scriptblock]::Create($exe)'}
How to fix the error:
The filename, directory name, or volume label syntax is incorrect.
+ CategoryInfo : NotSpecified: (The filename, d...x is incorrect.:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
+ PSComputerName : remote_computer
You definitely don't need to create a new script block for this scenario, see Bruce's comment at the bottom of the linked article for some good reasons why you shouldn't.
Bruce mentions passing parameters to a script block and that works well in this scenario:
$exe = 'setup.exe'
invoke-command -ComputerName $j -Credential $credentials -ScriptBlock { param($exe) & "C:\share\$exe" } -ArgumentList $exe
In PowerShell V3, there is an even easier way to pass parameters via Invoke-Command:
$exe = 'setup.exe'
invoke-command -ComputerName $j -Credential $credentials -ScriptBlock { & "C:\share\$using:exe" }
Note that PowerShell runs exe files just fine, there's usually no reason to run cmd first.
To follow the article, you want to make sure to leverage PowerShell's ability to expand variables in a string and then use [ScriptBlock]::Create() which takes a string to create a new ScriptBlock. What you are currently attempting is to generate a ScriptBlock within a ScriptBlock, which isn't going to work. It should look a little more like this:
$exe = 'setup.exe'
# The below line should expand the variable as needed
[String]$cmd = "cmd /c 'C:\share\$exe'"
# The below line creates the script block to pass in Invoke-Command
[ScriptBlock]$sb = [ScriptBlock]::Create($cmd)
Invoke-Command -ComputerName $j -Credential $credentials -ScriptBlock $sb
I'm new to PowerShell scripting. I'm struggling with the MS documentation and finding few examples to work with.
I'm trying to automate the weekly download of a large txt file from ntis.gov with a BitsTransfer script. I'm using .ps1 script because apparently SSIS can't do this without writing .NET code.
Access to this text file is via https: with an NTIS issued username and password. How can I specify (hard code) the password into the authentication string? I know this is bad practice. Is there a better way to do this?
My script looks like this-
$date= Get-Date -format yyMMdd
Import-Module BitsTransfer
$Job = Start-BitsTransfer `
-DisplayName DMFweeklytrans `
-ProxyUsage AutoDetect `
-Source https://dmf.ntis.gov/dmldata/weekly/WA$date `
-Destination D:\Test.txt `
-Authentication Basic `
-Credential "myIssuedUsername" `
-Asynchronous
While (($Job.JobState -eq "Transferring") -or ($Job.JobState -eq "Connecting")) {sleep 5}
Switch($Job.JobState)
{
"Transfer Completed" {Complete-BitsTransfer -BitsJobs $Jobs}
default {$Job | Format-List}
}
When you have to provide credentials in non-interactive mode, you can create a PSCredential object in the following way.
$secpasswd = ConvertTo-SecureString "PlainTextPassword" -AsPlainText -Force
$yourcreds = New-Object System.Management.Automation.PSCredential ("username", $secpasswd)
$Job = Start-BitsTransfer `
-DisplayName DMFweeklytrans `
-ProxyUsage AutoDetect `
-Source https://dmf.ntis.gov/dmldata/weekly/WA$date `
-Destination D:\Test.txt `
-Authentication Basic `
-Credential $yourcreds `
-Asynchronous
I am trying to use System.EnterpriseServices to uninstall a c# com+ component, replace the dll and reinstall the new version.
The problem is that when I get to the line copy-item the script always fails because System.EnterpriseSerivces is locking the destination file. If I break the script up into two sections one that calls UnistallAssembly and a second that does the copy and calls InstallAssembly everything works.
Any ideas for forcing system.enterpriseservices to release dll?
$comRoot = "C:\Comroot\"
[void][System.Reflection.Assembly]::LoadWithPartialName("System.EnterpriseServices")
[System.String]$applicationName = "My App Name";
[System.String]$typeLibraryName = $null;
$objAdmin = new-object -com COMAdmin.COMAdminCatalog
$objAdmin.ShutdownApplication("$applicationName");
$objAdmin = $null
$helper = New-Object System.EnterpriseServices.RegistrationHelper
$helper.UninstallAssembly("$comRoot\$StepName.dll", $applicationName)
$helper = $null
$applicationName = $null
[gc]::collect()
[gc]::WaitForPendingFinalizers()
"SOURCE : $BranchPath\Steps\$StepName\bin\Debug\"
"DESTINATION : $comRoot"
copy-item "$BranchPath\Steps\$StepName\bin\Debug\*$StepName*" -destination "$comRoot" - force
$helper = New-Object System.EnterpriseServices.RegistrationHelper
$helper.InstallAssembly("$comRoot\$StepName.dll", [ref] $applicationName, [ref] $typeLibraryName, [System.EnterpriseServices.InstallationFlags]::ConfigureComponentsOnly);
"Install Complete <$typeLibraryName>"
Read-Host "Press any key to exit"
I wonder if it is possible the uninstall isn't finished by the time you attempt the copy? That is, is the call to UninstallAssembly sync or async? One way to work around "file in use" issues is to attempt to rename the file using a tool like the SysInternals MoveFile.exe and then install the new version.