Powershell ExecutionPolicy is wrong when run through VisualStudio - visual-studio

I am trying to run a powershell script as part of my Pre-Build on a VS2005 project. I have run
$> powershell Set-ExecutionPolicy UnRestricted
from a command line before the build and I can run the same script from from the command line. However when the script is run as part of the Pre-Build step it fails with
The execution of scripts is disabled on this system.
Please see “get-help about_signing” for more details.
The script works on a co-worker's x32 XP machine, but not on my x64 Windows7 machine.

Did you set the execution policy in both the 64 and 32 bit Powershell environments? Your 64 bit machine will have both, and each has it's own executionpolicy setting.

Related

Microsoft Deployment Workbench chocolatey problem

I am currently testing Microsoft Deployment Workbench for automated Windows installation.
I have created a workflow with Windows 11 and would like to install the various programs via chocolatey after the Windows 11 installation.
Here you can see my workflow:
chocolatey is installed with a .bat script using:
command line: cmd.exe /c "%SCRIPTROOT%\BTNHD\chocoinstall.bat"
with the following content:
#powershell -noProfile -ExecutionPolicy unrestricted -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
then we restart the computer
then the script is started with the different programs, which looks like this:
command line: cmd.exe /c "%SCRIPTROOT%\BTNHD\installtemplate.bat"
with the following content:
choco install firefox --yes
choco install vlc --yes
Unfortunately it installs only the first software in the list at step 3, in my case Firefox and after that it takes a while and aborts with these error messages:
Now I have already tried the following things:
the reboot removed unfortunately no improvement
for each program a separate script and accordingly a separate installation step
tested other programs
changed the script
unfortunately there is nothing in the chocolatey log that can help me.
If I start the script manually, but everything works fine.
I currently do not know what to do and hope someone can help me, if there is any information missing, please let me know.
Thank you!

Powershell cannot be loaded because running scripts is disabled on this system

My question related to yarn. Before when I start create projects I installed with npm.
After a long time when I want to start running with yarn it shows the following error:
yarn : File C:\Users\pc\AppData\Roaming\npm\yarn.ps1 cannot be loaded because running scripts is disabled on this system.
(in Windows machine, Powershell)
Windows: 10
I tried with git bash terminal it worked!
but not in my powershell terminal
I have just fixed it by myself, anyway I am going to post answer here:
//open windows command Power shell as administrator and run command
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted
Set-ExecutionPolicy Unrestricted

Kicking off a WSL bash-based build from Visual Studio 2015

I recently started using the Windows Subsystem for Linux (WSL) to see if my Linux Makefile & arm-none-eabi-gcc based microcontroller project would build "natively" in Windows. To my surprise, the tool chain and Linux based development tools installed and worked perfectly on first go, without any modifications to the Makefile.
So that got me thinking to try doing all my code editing in Visual Studio using the IDE features while doing the actual build in the Linux & bash environment provided in WSL.
Unfortunately, when specifying a "Build Command Line" in the NMake options for my Visual Studio project, putting in "C:\Windows\System32\bash.exe build.sh" doesn't work because:
'C:\Windows\System32\bash.exe' is not recognized as an internal or external command,
operable program or batch file.
This is strange to me because I specified the full path and it couldn't find the WSL bash executable, and also attempting to add it as an "External Tool" doesn't seem to work because the executable doesn't show up in the selection window despite being able to see other executables in the same directory.
Some off topic opinion: If Microsoft can make Visual Studio and WSL work together seamlessly then I would likely switch from my Ubuntu virtual machine setup for a WSL based development environment.
Here's how you have to do it:
Nmake is not a 64-bit application, so when it tries to use Windows utilities and system32, WoW64 tricks it into looking in a different location.
The way you have to launch it from a 32-bit application is:
%windir%\sysnative\bash.exe
However, your command is also malformed. You will need to do it like this:
%windir%\sysnative\bash.exe -c "sh build.sh"
or maybe
%windir%\sysnative\bash.exe -c "./build.sh"
if DriveFS permissions allow execution.
otherwise it will attempt to execute build.sh as a command in your linux user's $PATH.
Source:
https://github.com/Microsoft/BashOnWindows/issues/870
This is what I have in my Build Command Line setting. It works fine.
start /WAIT %windir%\sysnative\bash.exe -c "cd /mnt/d/Projects/IoT/ESP8266/;./gen.sh -m DEBUG; read -n 1; exit;"

How to use Neo4j in command prompt without running as administrator

I am trying to use Neo4j 3.0.3 (zip file) command line tools in the command prompt on Windows 10. The problem is that it won't execute the files unless I run the command prompt as administrator. This is an issue for me because I can't run the command prompt as administrator on my machine I use for production. How can I run the Neo4j command prompt tools (neo4j-import.bat, etc.) without administrator mode? Is it possible?

Easiest/shortest command to run a PowerShell script as a build event in Visual Studio

Just getting started with PowerShell. I was running DOS .bat files in my post build events in VS and wanted to graduate up to PowerShell. Bat files were easy...CALL something.bat. I tried to do that with a PowerShell ps1 file and my trial-and-erroring got me to the following (first thing that worked...tried all the simple things first, obviously):
powershell -command "& {(powershell '$(ProjectDir)test.ps1')}"
Is there a shorthand version of this? I think the only thing that really bothers me is the redundant calls to the powershell executable, but that's probably only required because .ps1 files open in notepad by default on my machine (and I should keep the redundancy for deployment on other systems so I'm not reliant on the default program for a file type). Anyway, if there's unnecessary redundancy here, I'd love to know.
I'm very new to PowerShell, so any related insight is always appreciated.
I've used PowerShell as a post-build event in the past; now I lean towards using psake
(super simple build system) or just running a raw PowerShell script. Post-build events get messy, are inflexible, and have few advantages over doing the same thing in a build script.
EDIT: If you are still interested in using a post-build script, I've answered the question before here
According to the MSN, this should work nice:
powershell.exe "$(ProjectDir)test.ps1"
Edit: Found this
powershell.exe "& ""$(ProjectDir)test.ps1"""
I didn't check any MSDN, it simply works:
powershell $(ProjectDir)test.ps1
Btw. don't forget to set run privileges for BOTH versions of PowerShell -- 32-bit and 64-bit.
I was sort of happy with the elegant powershell $(ProjectDir) solution detailed here, but I ran into problems when starting/stopping IIS App Pools via WebAdministration's Start-WebAppPool and Stop-WebAppPool
I had better success with:
%WINDIR%\SysNative\WindowsPowerShell\v1.0\powershell.exe
i.e.
%WINDIR%\SysNative\WindowsPowerShell\v1.0\powershell.exe -Command "$(ProjectDir)Powershell\Stop-AppPool.ps1"
The reason turned out to be mixing of architectures, as detailed here (in the section "Using Windows PowerShell Scripts to Automate Tasks in Visual Studio"):
It's important that you use the virtual path of %WINDIR%\SysNative and
not the actual path of C:\Windows\System32. The reason for this is
that Visual Studio 2010 is a 32-bit application that needs to call the
64-bit version of powershell.exe to successfully load the
Microsoft.SharePoint.Powershell snap-in.

Resources