I can't login to Windows OpenSSH is my default shell is not powershell. If it is, then
reg add HKLM\SOFTWARE\OpenSSH /v DefaultShell /d C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe
makes the login work.
However, gitlab uses bash, which isn't available on power shell, so it uses pwsh.exe. However, if I set
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "$PSHOME\pwsh.exe" -PropertyType String -Force
as suggested here https://docs.gitlab.com/runner/executors/virtualbox.html, then SSH login won't work. If I leave powershell.exe, then it works but then it can't use bash
Related
We have an EC2 instance with a Files Share. Until now we could access it via UNC like so \\files.server.com.
Now we've started using packer and Ansible to setup our servers in deployment. After sysprep all the credentials get deleted and we need to create the access once again using the UserData script.
One more thing we need to give this access to all of our users because we have special user for our Windows service.
I have tried many things and still no luck, from New-PSDrive, NET USE,MapNetworkDrive, CredentialsManager and so on.
I would appreciate some assistance with this.
I do something similar, but I use the commands: section of a configSet within CloudFormation:
commands:
10-Create-Local-Fileshare-Directory:
command: >-
powershell.exe -Command New-Item "D:\Shared" -type directory
waitAfterCompletion: '0'
11-Create-Fileshare:
command: >-
powershell.exe -Command New-SmbShare -Name my-fileshare -Path "D:\Shared"
waitAfterCompletion: '0'
12-Grant-Fileshare-Permissions:
command: >-
powershell.exe -Command Grant-SmbShareAccess -Name my-fileshare -AccountName Everyone -AccessRight Change -Force
waitAfterCompletion: '0'
You could do the same if you're using CloudFormation or just pull out the Powershell commands you need.
I have a program that I would like to run daily on Azure. Is it possible to start up the VM and login to windows 10 automatically? I have scheduled the VM to start up and shut down, but I have not found a way to login to windows yet. Any suggestions?
Thanks!
Run this to get vm autologin configured (i did it during deployment via Powershell extension)
$RegPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
Set-ItemProperty $RegPath "AutoAdminLogon" -Value "1" -type String
Set-ItemProperty $RegPath "DefaultUsername" -Value "$username" -type String
Set-ItemProperty $RegPath "DefaultPassword" -Value "$password" -type String
I am trying to use the Web Administration module in a powershell script to deploy a handful of IIS websites and application pools using the visual studio post build event command line. When I run the script without using the web administration module the script succeeds, however I get an access denied error when they are included.
I have visual studio running as administrator
I have tried all sorts of flavor of setting the execution policy, but right now this is what I have (I have tried running both 32 and 64 bit versions of powershell):
cd $(ProjectDir)
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -NoProfile -NonInteractive -File "SetupLocalEnvironment.ps1" 2> nul
Looking for some assistance as my research is starting to reach the fruitless point. Thanks!
Here is the powershell script:
Import-Module WebAdministration
$FNMAWorkSpaceDirectory = "x"
# Do not edit below
Remove-Website -Name EDI
Remove-Website -Name WebAPI
Remove-WebAppPool -Name EDIAppPool
Remove-WebAppPool -Name WebAPIAppPool
New-WebAppPool EDIAppPool
New-WebSite -Name EDI -Port 124 -PhysicalPath "thePath" -ApplicationPool "thePool"
New-WebBinding -Name "EDI" -Protocol "https" -IPAddress "*" -Port 125
New-WebAppPool WebAPIAppPool
New-WebSite -Name WebAPI -Port 123 -PhysicalPath "thePath" -ApplicationPool "WebAPIAppPool"
Set-Location Cert:\LocalMachine\My
$certHash = (Get-ChildItem -DnsName "theCertName").Thumbprint
$guid = [guid]::NewGuid()
$Command = "http add sslcert ipport=0.0.0.0:125 certhash=$certHash appid={$guid}"
$Command | netsh
exit
I have been trying to enable or disable a Local group policy with powershell to automate the process, I tried installing Remote Server Administration Tools but it's module in powershell needs the pc to be in a domain.
Is there any way to enable\disable a Local group policy with powershell?
Use the registry (note that this requires elevation):
Set-ItemProperty -Path <HKLM:RegistryPath> -Name <PropertyToChange> -Value <NewValue>
Example (Enabling Search Suggestions from Edge):
Set-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\MicrosoftEdge\SearchScopes" -Name "ShowSearchSuggestionsGlobal" -Value 1
I am getting an error while executing a remote PowerShell script. From my local machine I am running a PowerShell script that uses Invoke-Command to cd into a directory on a remote Amazon Windows Server instance, and a subsequent Invoke-Command to execute script that lives on that server instance. The script on the server is trying to git clone a repository from GitHub. I can successfully do things in the server script like "ls" or even "git --version". However git clone, git pull, etc. result in the following error:
Cloning into 'MyRepo'... + CategoryInfo : NotSpecified: (Cloning into 'MyRepo'...:String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError
This is my first time using PowerShell or a Windows Server. Can anyone provide some direction on this problem.
The client script:
$s = new-pssession -computername $server -credential $user
invoke-command -session $s -scriptblock { cd C:\Repos; ls }
invoke-command -session $s -scriptblock { param ($repo, $branch) & '.\clone.ps1' -repository $repo -branch $branch} -ArgumentList $repository, $branch
exit-pssession
The server script:
param([string]$repository = "repository", [string]$branch = "branch")
git --version
start-process -FilePath git -ArgumentList ("clone", "-b $branch https://github.com/MyGithub/$repository.git") -Wait
I've changed the server script to use start process and it is no longer throwing the exception. It creates the new repository directory and the .git directory but doesn't write any of the files from the github repository. This smells like a permissions issue. Once again invoking the script manually (remote desktop into the amazon box and execute it from powershell) works like a charm.
Anytime you're calling an external executable from PowerShell, I highly recommend using Start-Process. The Start-Process cmdlet handles command line arguments much better, as compared to calling the executables directly.
Important: You must also be aware that if you run two separate Invoke-Command commands (unless you're using the -Session parameter) that you will be operating in two completely distinct PowerShell Remoting sessions! If you use the cd (aka. which is an alias for Set-Location) command, the results of that command will not persist into the new session when you run your Git command.
$GitExe = '{0}\path\to\git.exe' -f $env:SystemDrive;
$ArgumentList = 'clone "c:\path\with spaces\in it"';
Start-Process -FilePath $GitExe -ArgumentList $ArgumentList -Wait -NoNewWindow;
There is also a -WorkingDirectory parameter on the Start-Process cmdlet, that allows you to specify the Working Directory for a process. Instead of using the Set-Location cmdlet to set the "current directory" of the PowerShell session, you're probably better off specifying the full path to the working directory for the process. For example, let's say you had a Git repository in c:\repos\repo01, and your Git exe was in c:\git. You shouldn't worry so much about where PowerShell's "current directory" is, and rather focus on specifying the full paths to:
The Git executable
The Git repositories
Here's an example of how to achieve that:
Start-Process -FilePath c:\git\git.exe -ArgumentList 'clone "c:\repos\repo01" "c:\repos\repo02"" -Wait -NoNewWindow;
Note: I don't know the Git commands, but you should be able to adjust the value of the $ArgumentList variable above, to make it work for you. In PowerShell, you can put double-quotes inside of single-quotes, without having to worry about escaping them.