How do I get the appcmd to write commands? Using Windows 10. Getting this error:
'appcmd' is not recognized as an internal or external command, operable program or batch file.
Also, if I have used this command:
appcmd delete site "Default Web Site"
If I what to do the opposite - do I use add instead of delete?
Appcmd.exe is located at path %windir%\system32\inetsrv and by default is not listed in PATH variable. So in order to use this command you have to navigate to this folder first and then you can update IIS configuration using appcmd utility.
By the way appcmd.exe is available only to the Administrator account or to users who are members of the Administrators group on the computer.
And to your second question, yes opposite verb to DELETE is ADD.
More information can be found at documentation: https://technet.microsoft.com/en-us/library/jj635852(v=ws.11).aspx#BKMK_Start
Related
I have started using VSCODE for editing and running scripts.
If I run VSCODE as admin, I cannot access files on a network drive (mapped or otherwise).
If I don't run VSCODE as admin I cannot execute the PS scripts I need to.
Has anyone experienced something similar, or found a work around?
Since the Administrator account doesn't have the drive mappings your user account has, you can try accessing the Universal Naming Convention (UNC) path to the network resources/shares directly.
Format
\\<server-hostname-or-IP>\<share-name>\<directory-name>
Examples
\\server1\c$
\\server2\share\foo\bar
If you don't know the UNC paths for the mapped drives, run net use from a cmd.exe prompt under your user (not admin) account context. The UNC paths fall under the Remote column heading in the output, and should resemble the format outlined above.
Helpful Links
UNC paths
Net use
So we're setting up a release where we want to copy some artifacts to a target server in order to start a deploy. unfortunately when the task starts it errors out on the actual copy with the following error:
The term 'robocopy' 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.
However when checking both source and target machine the robocopy command (both from Powershell and CMD.exe run perfectly and presents the default robocopy starting screen.
We're using a private build agent running windows server 2016.
I've checked PATH variables and C:\Windows\System32 is in the list and running a search on both systems gives back robocopy.exe in the same directory.
running the task on a hosted agent makes it run fine. So it definitely is a local issue, just don't see where this might be coming from.
results of echo %PATH% and robocopy on the build agent:
Results of the Release with the failing task:
As requested by Shayki the task definition:
for some unknown reason the %PATH% variable would show C:\Windows\System32 when doing echo %PATH% however when going through the environment variables inside control panel there was no entry for it inside the PATH environment variable.
Added the C:\Windows\System32 folder back into PATH system environment Variables (and putting it on top) fixed it for us.
I have a very simple command in powershell to start SSH tunnels:
ssh -N -L 28777:localhost:28778 myapp-db
What's the simplest way to make this a service, so I can run:
start-service db-tunnel
etc on Windows 10? I've read an old article on doing this and it involves using C#, which seems way too complex for such a simple task.
PowerShell is not necessary. Here's one way:
Install the Windows Server 2003 Resource Kit Tools package somewhere and get the files instsrv.exe and srvany.exe.
Use srvany.exe to create the service using the ssh.exe program and its parameters using the information in Microsoft help article 137890.
For example:
instsrv "SSH Server" "C:\Program Files (x86)\Resource Kit Tools\srvany.exe"
Of course, specify whatever service name you want and the path and filename of srvany.exe.
Next, use the registry editor to go to HKLM\SYSTEM\CurrentControlSet\Services\SSH Tunnel (or whatever you named the service) in the registry and create a Parameters subkey. In the Parameters subkey create an Application value (REG_SZ type):
C:\Program Files (x86)\ssh\ssh.exe
(or whatever - the path and filename to your ssh executable).
You can also create the values AppDirectory (REG_SZ) to specify the starting directory for the executable, and AppParameters (REG_SZ) to specify the parameters to the executable; e.g.:
-N -L 28777:localhost:28778 myapp-db
You can substitute the use of the NSSM tool mentioned by BenH in his comment if you prefer that tool and are allowed to use third-party software.
To make something into a service, you would need to compile your script into an executable. This can be done via PS2EXE.
What may work just as well for you is making a function in powershell, Start-DbTunnel, and making that import into your powershell session on start. You can do this by loading functions in the foloowing path:
$PSprofilePath\Microsoft.PowerShell_profile.ps1
or for the ISE
$PSprofilePath\Microsoft.PowerShellISE_profile.ps1
Inside those files, I have
$PSprofilePath = "C:\Users\cknutson\Documents\WindowsPowershell"
$items = Get-ChildItem "$PSprofilePath\functions"
#Set-Location "$PSprofilePath\functions"
$items | ForEach-Object {
. $_.FullName
}
Set-Location C:\
Any scripts containing functions, or otherwise will be run each time you open a powershell host.
I tried to install Posh-Git to use ssh with Powershell.
I followed the instructions here
The file here was not digitally signed so I changed the Execution Policy to install it. I then (for whatever reason) decided not to use this so I removed the file.
Now whenever I start Powershell I get an error similar to the below:
The term 'C:\xxx\xxx\profile.example.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program.
How do I stop this error message from appearing each time I start Powershell?
You need to edit your PowerShell profile and remove that line from there. The easiest way would be (from within your PowerShell):
notepad $profile
or alternatively you can look up your profile with $profile and edit the file there.
Consult this for further reading: https://blogs.technet.microsoft.com/heyscriptingguy/2012/05/21/understanding-the-six-powershell-profiles/
I want to know if there is an existing command or script to retrieve the Canonical Name Record (CNAME) for a given computer or server. I would like to use this via CMD/Powershell I don't mind if such command or script uses the Windows Registry Editor (regedit).
The hostname program/command should give you the DNS name of the local machine, whereas the shell command echo %COMPUTERNAME% should show you the NetBIOS name (which might be different).