How to reserve a static IP for Azure Virtual Machines? - powershell

Amazon have Elastic IP that you can assign to an instance,
How can I do that with Azure for existing VM?
(I don't want to change all my DNS entries if the IP changes)
I found some articles about running power shell commands
1. http://michaelwasham.com/windows-azure-powershell-reference-guide/using-reserved-ip-addresses-with-microsoft-azure-virtual-machines/
2. http://azure.microsoft.com/blog/2014/05/14/reserved-ip-addresses/
3. http://azure.microsoft.com/blog/2014/04/22/static-internal-ip-address-for-virtual-machines/
But the commands are not recognized on my server (Windows server 2012 R2)
Any idea how can I do that?
This is the error that I'm getting on Power Shell:
PS C:\> New-AzureReservedIP – ReservedIPName "137.117.11.18" –Label "people-dns-ip" –Location "US West"
New-AzureReservedIP : The term 'New-AzureReservedIP' 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 line:1 char:1
+ New-AzureReservedIP – ReservedIPName "137.117.11.18" –Label "people-dns-ip" –Loc ...
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (New-AzureReservedIP:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

Sounds like you are missing the requiered CMD for PowerShell. Please download the Microsoft Webinstaller:
Download Microsoft Web-Installer
and do an fresh installation of Microsoft PowerShell. After this you should be able to use the "New-AzureReservedIP" command. Maybe you are running an old version of PowerShell without this CMDlet.
For more information about installation PowerShell, see: Configure and Install PowerShell (Azure)

Related

Powershell .ps1 scripts won't run / don't exist?

I’ve started having the strangest problem with running powershell scripts in the last few weeks…
They all display this error message as if the file doesn’t exist?
Full console output below showing that I proved the file does exist with the Get-Content cmdlet…
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Try the new cross-platform PowerShell https://aka.ms/pscore6
PS H:\> C:
PS C:\> cd C:\Users\Public
PS C:\Users\Public> .\test3.ps1
.\test3.ps1 : The term '.\test3.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 line:1 char:1
+ .\test3.ps1
+ ~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (.\test3.ps1:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
PS C:\Users\Public> get-content test3.ps1
Get-Process | Out-GridView -Wait
PS C:\Users\Public> .\test3.ps1
.\test3.ps1 : The term '.\test3.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 line:1 char:1
+ .\test3.ps1
+ ~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (.\test3.ps1:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
PS C:\Users\Public>
I’ve already got my execution policy set to unrestricted.
Any suggestions
OS
Windows 10 Enterprise
Version 1909 (OS Build 18363.959)
PS C:\Users\Public>> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      5.1.18362.752
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.18362.752
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
UPDATE:
I can get a different result when set to run in PowerShell version 2...
PS C:\Users\Public> powershell -version 2 -ExecutionPolicy bypass -file test3.ps1
Out-GridView : A parameter cannot be found that matches parameter name 'Wait'.
At C:\Users\Public\test3.ps1:1 char:33
+ Get-Process | Out-GridView -Wait <<<<
    + CategoryInfo          : InvalidArgument: (:) [Out-GridView], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.OutGridViewCommand
PS C:\Users\Public> powershell -version 3 -ExecutionPolicy bypass -file test3.ps1
The term 'C:\Users\Public\test3.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.
    + CategoryInfo          : ObjectNotFound: (C:\Users\Public\test3.ps1:String) [], ParentContainsErrorRecordExceptio
   n
    + FullyQualifiedErrorId : CommandNotFoundException
PS C:\Users\Public>
Presumably the -Wait argument just wasn't available in version 2. I can use this now to run scripts in version 2, but obviously that's quite limited functionality.
UPDATE 2:
I had completely forgot that I had this exact problem earlier in the year; and even posted a Question about it over on Superuser…
https://superuser.com/questions/1536086/powershell-wont-run-ps1-files
I had marked up an answer that I thought it was caused by the transition from using CAG to CheckPointVPN (back in March when remote-working was becoming a long-term thing); and it was somehow resolved after going into the office and connecting directly to the network?
This time however; connecting directly to the office network isn’t resolving it.
Only thing else like that that has changed recently; was that IT setup support for Windows Password 30 day resets when working remotely (previously it wasn’t working, so the 30 day reset was previously disabled during lockdown).  I had reset my password remotely just before taking leave in August, and when I came back I was unable to run powershell scripts?
I have tried resetting my password while in the office, but it hasn’t fixed the problem.
I’m stuck for what else I can check??
This problem was down to AppLocker preventing the script from running.
In order to check if this is the cause for your problem, open the Event Viewer and navigate to
> Applications and Services Logs
> > Windows
> > > AppLocker
> > > > MSI and Script
Look for any Error log entries and it should state something like
%OSDRIVE%\USERS\PUBLIC\TEST3.PS1 was prevented from running.
In my case this change was applied by IT security 2 months back; and since then the IT helpdesk have been slowly dealing with the complaints and whitelisting selected folder directories to resolve.
For some reason my colleagues weren't impacted by the change when they should have been; which lead me to believe it was a problem with my machine or user.
In order not to let this question go by without answer, here my comment as answer
Seeing what you have already tried, I think there is a problem with one of the dll's in your system. Since PowerShell is part of Windows 10, you cannot uninstall/reinstall it as far as I know.
What you can try is to repair missing or corrupted system files.
Open an elevated command prompt and run
dism /online /cleanup-image /restorehealth
This will use Windows Update to provide the files that are required to fix corruptions, so an internet connection is required. If that is out of the question, you can specify another source with switch
/Source:<PathToFreshWindowsFiles>
When that finishes, type
sfc /scannow
to scan all protected system files, and replace corrupted files with a cached copy that is located in a compressed folder "%WinDir%\System32\dllcache"
Both actions take quite some time to finish.
When done reboot your computer.
In my case, I had this error and the issue was a file the script was trying to access did not exist. I ran the script in powershell_ise.exe and clicked the Run Script button and a much clearer message was displayed:
Cannot find path 'C:\logs\logfile.log' because it does not exist.
I created the file and the script ran successfully.

How to run IoTCorePShell.cmd

I try to port Prolific USB to COM converter for solve my other problem: List UART -> COM converter in Windows Device Portal
I found this manual: https://learn.microsoft.com/en-us/windows/iot-core/learn-about-hardware/peripheraldrivers and copied all necessary files to separate folder:
oem6.inf
ser2pl64.sys
serenum.sys
I installed:
Windows 10 IoT Core Packages
Windows Assessment and Deployment Kit including Windows PE add-on
Now I try to launch IoTCorePShell.cmd for run New-IoTInf2Cab as mentioned in the manual.
I tried both cmd and Power Shell, both with administrator rights and without.
In Power Shell I get:
PS C:\Users\olga\Desktop\COMDriver> New-IoTInf2Cab
New-IoTInf2Cab : The term 'New-IoTInf2Cab' 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 line:1 char:1
+ New-IoTInf2Cab
+ ~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (New-IoTInf2Cab:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
How can I run New-IoTInf2Cab?
OK, it was necessary to clone the repository.
The IoTCorePShell.cmd stay in the root.
https://github.com/ms-iot/iot-adk-addonkit

ObjectNotFound Error while using cmdlet to access AWS IAM

I am trying to generate AWS API gateway access key through powershell. However, everytime I try to use any cmdlet it throws an error:
For example:
Get-AWSCredential -ListProfileDetail
will result in an error like this:
Get-AWSCredential : The term 'Get-AWSCredential' 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 line:1 char:1
+ Get-AWSCredential -ListProfileDetail
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-AWSCredential:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
When I display the list of commands through Get-Command the AWS cmdlets do not pop up.
Any idea what could be the problem?
Long story short, run this: Install-Package -Name AWSPowerShell
You may need to run PS as an Administrator for the Install-Package command to work. Additionally, you may be prompted to install 'nuget', answer yes. If you receive the security warning about PSGallery, answer yes.
Here is Amazon's docs on PS cmdlets: http://docs.aws.amazon.com/powershell/latest/userguide/pstools-getting-set-up.html

Not able to execute AWS Powershell tool cmdlet in TFS Post build script

I am trying to execute the few aws cmdlet command in post build script with TFS build. I have a AWS SDK tool is installed in build controller. I am able to run the same commands manually in Build controller. But when i invoke those commands in TFS post build script. It's giving me error that its not able to find the cmdlet installed on the build controller. I tried to change the execution policy but didn't help. I have an execution policy - bypass right now. script is executing but only the commands is not able to execute. I am thinking that it's issue because of something like Execution policy. Do we need to check anything else same like execution policy while we invoke any third party cmdlet from power shell.
Commands:
Set-AWSCredentials -AccessKey -SecretKey
Set-DefaultAWSRegion -Region us-east-1
Write-S3Object -BucketName agero-source-package -File "\\b tfadfa\adfa\adf\asdf\adsf\asdf\asd\xyz.zip"
Error:
Set-DefaultAWSRegion : The term 'Set-DefaultAWSRegion' 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 \\b-tfsbc001wv\c$\MV\BuildETA-API.ps1:41 char:26
+ cd "\\b-tfsbc001wv\C$" | Set-DefaultAWSRegion -Region us-east-1
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Set-DefaultAWSRegion:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Write-S3Object : The term 'Write-S3Object' 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 \\b-tfsbc001wv\c$\MV\BuildETA-API.ps1:43 char:26
+ cd "\\b-tfsbc001wv\c$" | Write-S3Object -BucketName agero-source-package -File " ...
+ ~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Write-S3Object:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
From the error messages, it would appear that the AWSPowerShell module cannot be found/automatically loaded by whatever account the TFS build process is running as.
Check that the module is installed to a globally available location under which the version of PowerShell you have searches for modules or, that the path to the module folder is present in the $PSModulePath environment variable for the TFS build account.
I got the same error on my TFS Build Agent:
Set-DefaultAWSRegion : The term 'Set-DefaultAWSRegion' 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.
After I installed AWS Command Line Interface x64 bit (AWSCLI64) I was able to set the Set-DefaultAWSRegion by stepping over the line of code.
I was getting this error until I ran Powershell using "Run as Administrator." So the problem might be with permissions.

The term 'get-splogevent' is not recognized as the name of a cmdlet

I'm new to Sharepoint... and I'm trying to deploy a simple web part.
When I do deploy it and place it on a page, I get an error with a correlation id.
Now, I'm trying to get details about the error, and using Powershell I type...
get-splogevent | ?{$_Correlation -eq "bcce1b39-f277-4b2b-b8f8-4c113a30f193" }
But it's giving me an error....
The term 'get-splogevent' 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 line:1 char:15
+ get-splogevent <<<< | ?{$_Correlation -eq "bcce1b39-f277-4b2b-b8f8-4c113a30f193" }
+ CategoryInfo : ObjectNotFound: (get-splogevent:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Any ideas as to what I'm doing wrong?
Most likely you are on an ordinary Powershell session. The Sharepoint management snap-in is not being loaded, so cmdlet is not found. Take a look at an article that describes how to load the snap-in automatically to all Powershell sessions.
The snap-in is loaded manually like so,
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
I was starting the solo powershell instead of the sharepoint one. In the task bat there is "Sharepoint 2010 Management Shell", using that worked.