I am trying to use a PowerCli commandlet to create a new virtual machine
New-VM -ResourcePool vfcplvmh0009 -Version v11 -Name TestServer22 -Datastore 0031_A_Normal001 -DiskGB 100 -DiskStorageFormat EagerZeroedThick -MemoryGB 4 -NumCpu 2 -CoresPerSocket 2 -Template Win2012-STDR2_GoldenImage -Confirm $false
However it will not run and displays the following error message
New-VM : Parameter set cannot be resolved using the specified named
parameters. At line:1 char:1
+ New-VM -ResourcePool vfcplvmh0009 -Version v11 -Name TestServer22 -Da ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-VM], ParameterBindingException
+ FullyQualifiedErrorId : AmbiguousParameterSet,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM
I am unsure as to why this error message is being generated as all the parameters and data for them appear to be correct.
Looks like you have a syntax error. The correct format for -Confirm in PowerCLI should be:
-Confirm:$false
This is a common mistake when using the -Confirm parameter.
Also, you cannot use the template parameter because it is a part of a different parameter set.
If you remove the -Template parameter, then you should be able to create the VM.
In VMWare, the template will already have the CPU, RAM, and HDisk information to describe the vmdk file. You have to use one or the either. Can't use both.
The correct code should be like this:
New-VM -ResourcePool vfcplvmh0009 -Version v11 -Name TestServer22 -Datastore 0031_A_Normal001 -DiskGB 100 -DiskStorageFormat EagerZeroedThick -MemoryGB 4 -NumCpu 2 -CoresPerSocket 2 -Template Win2012-STDR2_GoldenImage -Confirm:$false
You can read more about Users Requesting Confirmation here
Related
Summary:
I have several functions that are placed on a remote windows server built for implicit remoting. However, I am unable to utilize the Get-Help cmdlet to show the synopsis that I put into each of the functions that I created, so these are not native powershell cmdlets. The get-help cmdlet works fine with the scripts are running locally.
Question:
Is it not possible to use Get-Help with implicit remoting?
Edit 1.
Attempting Briantists fix
PS> $module = Import-Module 'tmp_2c0mhyix.ivb' -PSSession $sessVar -PassThru
Import-Module : Failure from remote command: Import-Module -Name 'tmp_2c0mhyix.ivb': The specified module 'tmp_2c0mhyix.ivb' was not loaded because no valid module file was found in any module directory.
At line:1 char:11
+ $module = Import-Module 'tmp_2c0mhyix.ivb' -PSSession $sessVar-Pa ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (tmp_2c0mhyix.ivb:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
Tried this as well with out the module name as well.
PS> $module = Import-Module -PSSession $sessVar-PassThru
Import-Module : Parameter set cannot be resolved using the specified named parameters.
At line:1 char:11
+ $module = Import-Module -PSSession $sessVar-PassThru
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Import-Module], ParameterBindingException
+ FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.PowerShell.Commands.ImportModuleCommand
Implicit remoting is a strange beast. It creates proxy functions in a temporary module, and it's the proxy functions that get called locally.
After you call Import-PSSession, call Get-Module and you'll see one with a weird tmp name.
Alternatively, you can import the module initially using this method $module = Import-Module -PSSession $mySession -PassThru to get the module returned in a variable.
Then you can call Get-Command -Module $module to see the functions, but check out the definition:
Get-Command -Module $module | Select-Object -First 1 -ExpandProperty Definition
Shay Levy goes into detail about proxy functions here, and you can see that they do include instructions for Get-Help so that it can find the right help topic, but when the command is on the other side of the remoting, I don't think those would work.
I don't know if I've ever tried using help for functions imported that way, so maybe it actually does work and it's just a bug you've found, but I feel like this info would still be helpful.
Hello I am not powershell programmer and I learning right now using pluralsight and exericese file giving me error and I think it happening because or version change of Azure Powershell from 0.9.8 to version 1.0
Here is error :
c:\Pluralsight\chef\2-chef> .\Create-CourseEnvironmentARM.ps1
Switch-AzureMode : The term 'Switch-AzureMode' 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:\Pluralsight\chef\2-chef\Create-CourseEnvironmentARM.ps1:28 char:1
+ Switch-AzureMode AzureResourceManager -Verbose
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Switch-AzureMode:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Test-AzureResourceGroup : The term 'Test-AzureResourceGroup' 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:\Pluralsight\chef\2-chef\Create-CourseEnvironmentARM.ps1:32 char:5
+ if((Test-AzureResourceGroup -ResourceGroupName $GroupName) -eq $false){
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Test-AzureResourceGroup:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
New-AzureResourceGroupDeployment : The term 'New-AzureResourceGroupDeployment' 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:\Pluralsight\chef\2-chef\Create-CourseEnvironmentARM.ps1:44 char:1
+ New-AzureResourceGroupDeployment `
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (New-AzureResourceGroupDeployment:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
File Name :.\Create-CourseEnvironmentARM.ps1
I was searching error in google and confirm that azure power shell
deprecate function "Switch-AzureMode AzureResourceManager -Verbose"
https://github.com/Azure/azure-powershell/wiki/Deprecation-of-Switch-AzureMode-in-Azure-PowerShell
Switch-AzureMode AzureResourceManager -Verbose
Here is code from Create-CourseEnvironmentARM.ps1
Switch-AzureMode AzureResourceManager -Verbose
### Create Resource Group ###
if((Test-AzureResourceGroup -ResourceGroupName $GroupName) -eq $false){
New-AzureResourceGroup -Name $GroupName -Location $Location -Verbose
$ResourceGroup = Get-AzureResourceGroup -Name $GroupName
}
else {$ResourceGroup = Get-AzureResourceGroup -Name $GroupName}
$parameters = #{
'newStorageAccountName'="$StorageName";
'adminUsername'="$AdminUsername";
'dnsNameForPublicIP'="$PublicDNSName"
}
New-AzureResourceGroupDeployment `
-Name $DeploymentName `
-ResourceGroupName $ResourceGroup.ResourceGroupName `
-TemplateFile azuredeploy.json `
-TemplateParameterObject $parameters `
-Verbose
Please help me to correct this code. I think author is never update course and I am in middle of course. I hope someone help me to fix this problem.
There is no more "Switch-AzureMode" since v. 1.0.0 of the Powershell.
The ARM and ASM cmdlets exists together and live together. The ASM cmdlets are with unchanged names, but the ARM cmdlets are all now with RM in their name. Like:
Add-AzureRmAccount
Both the powershell cmdlets can be installed via Web Platform Installer.
More, when on Windows 10, the ARM cmdlets can be installed via PowerShell Gallery using the ofllowing commands (under Aministrative PowerShell console):
Install-Module AzureRM
Confirm all the questions being asked. Then run the
Install-AzureRM
Then you are done with the ARM module. Just make sure that your local execution policy is at least "RemoteSigned".
At the end, you will have to edit all your PowerShell scripts to match the new cmdlets and their parameters. Like the New-AzureResourceGroup is now New-AzureRmResourceGroup: https://msdn.microsoft.com/en-us/library/mt603739.aspx
I'm trying to run the following Azure Powershell cmdlet to provision a new Virtual Machine on a existing Cloud Service.
PS C:\> Get-AzureService | ft ServiceName
ServiceName
-----------
$AZURETEST-EUWEST0
$AZURETEST-JPWEST0
$AZURETEST-USEAST0
$AZURETEST-USWEST0
PS C:\> $image = "a699494373c04fc0bc8f2bb1389d6106__Windows-Server-2012-R2-201505.01-en.us-127GB.vhd"
PS C:\> New-AzureQuickVM -Windows -ServiceName "$AZURETEST-USEAST0" -name "AZURESVM-USE1" -ImageName $image -Password Password1 -AdminUsername admin -WaitForBoot
New-AzureQuickVM : ResourceNotFound: The deployment name '$AZURETEST-USEAST0' does not exist.
At line:1 char:1
+ New-AzureQuickVM -Windows -ServiceName "$AZURETEST-USEAST0" -name "AZURESVM-USE1" -Im ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [New-AzureQuickVM], CloudException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.PersistentVMs.NewQuickVM
New-AzureQuickVM : Sequence contains no matching element
At line:1 char:1
+ New-AzureQuickVM -Windows -ServiceName "$AZURETEST-USEAST0" -name "AZURESVM-USE1" -Im ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [New-AzureQuickVM], InvalidOperationException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.PersistentVMs.NewQuickVM
PS C:\>
What doesn't make sense is I'm getting an error that says my Cloud Service - or Deployment Name doesn't exist when you can clearly see it returned when I listed all the available Cloud Services!
First of all, admin as administrator account name will not work. It's a reserved word, once you get past the service name, it will break on this one.
Second, there's nothing wrong with your powershell command and I tested exactly with the same parameters to make sure. I can bet it's the "$" you used for the cloud service name that is being misinterpreted by the cmdlet.
Since you can't rename cloud services, create a new one without the "$" and try again to see if it works.
Update: This is what happens when i try to create CS from the portal with the "$" as first character:
"This field can contain only letters, numbers, and hyphens. The first
and last character in the field must be a letter or number.
Trademarks, reserved words, and offensive words are not allowed."
Try to enter all parameters inline without using named parameters (e.g $image). that solved it for me.
Here is a working example:
$image = "a699494373c04fc0bc8f2bb1389d6106__Windows-Server-2012-Datacenter-20160229-en.us-127GB.vhd"
$location = 'West Europe'
New-AzureQuickVM -Windows -Location $location -ServiceName "RamiSOTest1-cs" -name "RamiSOTest1-VM" -ImageName $image -Password 'RamiPass-1' -AdminUsername 'rami' -WaitForBoot
I'm stumped by this issue.
I've written a powershell script which I'm trying to use to import a GPO across multiple domains and then link it with new-gplink. I've made sure all servers have GP Powershell module installed and it's been working pretty well so far, however the issue I'm running into is that on some servers my command works fine on others I get the error, on the last step I'm getting an operations error one of my invoke-commands. Other commands work on the same server with invoke-command such as get-service, or even the import-GPO command that I use.
The error in question:
An operations error occurred. (Exception from HRESULT: 0x80072020)
+ CategoryInfo : NotSpecified: (:) [New-GPLink], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Microsoft.GroupPolicy.Commands.NewGPLinkCommand
+ PSComputerName : 10.0.0.10
The command:
Invoke-Command -ComputerName $serverip -scriptblock {New-GPLink -Name "GPO" -Target $args[0]} -ArgumentList $oupath -credential $cred
I've tried every version of this command I can imagine. without [0], without argument list, just using the server ip and replacing the target with the OU path and I still get the same error, such as below.
Invoke-Command -ComputerName $serverip -scriptblock {New-GPLink -Name "GPOName" -Target ou=users,ou=site,ou=domain,dc=server,dc=com} -ArgumentList $oupath -credential $cred
The way I have it working is a .csv with the server info, it gets imported into a foreach loop and then fed into the script. I have it grab credentials and feed through. I know everything else is working because my invoke-command to import the GPO worked, all servers I ran to successfully imported the GPO. I also know my OU paths are correct because I use them locally with another script to place computers where I want them. a sample line in the csv would be something like
servername, 10.0.0.10, domain.com, OU=user,OU=site,DC=domain,DC=com
I've also ran the command locally and get a similar error:
PS> New-GPLink -Name "GPO" -Target "ou=users,ou=Site,dc=domain,dc=com"
New-GPLink : A referral was returned from the server.
At line:1 char:1
+ New-GPLink -Name "GPO" -Target "ou=users,ou=site,dc=domain,d ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-GPLink], DirectoryServicesCOMException
+ FullyQualifiedErrorId : System.DirectoryServices.DirectoryServicesCOMException,Microsoft.GroupPolicy.Commands.NewGPLinkCommand
Please let me know if there are additional question or if you need additional info. I'm completely stumped by this issue and I appreciate any help you can provide. Thanks in advance.
Edit: All of my servers are at least 2008 R2 and are using powershell version 3,0,1,1
PS> $psversiontable.psversion
Major Minor Build Revision
----- ----- ----- --------
3 0 -1 -1
You need to specify a the domain in which your trying to apply the GPO, as well as a Domain Controller from the domain in question with the -Domain and -Server parameters respectively:
$OU = "ou=users,ou=Site,dc=domain,dc=com"
New-GPLink -Name "GPO" -Target $OU -Server "domain.com" -Domain "domain.com"
Instead of just using the domain name though, the proper way to do this, is to actually locate a Domain Controller, like so:
$DC = Get-ADDomainController -Discover -DomainName "domain.com" |Select -ExpandProperty HostName
New-GPLink -Name "GPO" -Target $OU -Server $DC -Domain "domain.tld"
Or in an environment where Get-ADDomainController is not available, you can emulate the DCLocator (aka. the underlying high-availability design of AD DS) behavior with .NET:
$DomainFqdn = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
$dctx = New-Object System.DirectoryServices.ActiveDirectory.DirectoryContext -ArgumentList "Domain",$DomainFqdn
$DomainController = $[System.DirectoryServices.ActiveDirectory.DomainController]::FindOne($dctx)
New-GPLink -Name "GPO" -Target $OU -Server $DomainController.Name -Domain $DomainFqdn
I am trying to setup an Endpoint-Server in my company and am struggling to connect to it. For testing I put a RcLogUtil Module in the Global Module Path
C:\windows\system32\WindowsPowershell\v1.0\Modules\RcLogUtil\
that exports the functions
'Out-LogToEventLog','New-LogMessage'
The Plan is to let a specific set of users access only those Logging-Functions.
I create a SessionConfiguration:
New-PSSessionConfigurationFile -Path C:\Scripts\LoggerEp.pssc `
-SessionType RestrictedRemoteServer `
-LanguageMode FullLanguage `
-ExecutionPolicy Unrestricted `
-ModulesToImport 'RcLogUtil' `
-VisibleFunctions 'Out-LogToEventLog' `
-VisibleCmdlets 'Split-Path'
Register it:
Register-PSSessionConfiguration -Path C:\Scripts\LoggerEp.pssc `
-Name loggerep `
-ShowSecurityDescriptorUI
And enter it on my local machine:
[W0216]> Enter-PSSession -ComputerName mka-ps-endpoint -ConfigurationName loggerep
Enter-PSSession : One or more errors occurred processing the module
'RcLogUtil' specified in the InitialSessionState object used to create
this runspace. See the ErrorRecords property for a complete list of
errors. The first error was: The term 'Split-Path' 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
+ Enter-PSSession -ComputerName mka-ps-endpoint -ConfigurationName loggerep
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (:) [Enter-PSSession], RunspaceOpenModuleLoadException
+ FullyQualifiedErrorId : ErrorLoadingModulesOnRunspaceOpen
The huge question now is.. why is the Session unable to find Split-Path? Or how do I tell the Endpoint to load that particular cmdlet?
I successfully tried the same with SessionType=’Default’ and it worked but with all the powershell clutter around it.
I would really apreciate any help I can get as I am stuck with this for quite some time now..
Thanks!
There is the option to disable each cmdlet in advance by using -SessionType Default with the -ScriptsToProcess 'C:\Scripts\LoggerEpStartup.ps1' Parameter when creating a SessionConfiguration.
New-PSSessionConfigurationFile -Path C:\Scripts\LoggerEp.pssc `
-SessionType Default `
-LanguageMode FullLanguage `
-ExecutionPolicy Unrestricted `
-ModulesToImport 'RcLogUtil' `
-VisibleFunctions 'Out-LogToEventLog' `
-ScriptsToProcess 'C:\Scripts\LoggerEpStartup.ps1'
C:\Scripts\LoggerEpStartup.ps1:
# Commands needed by PSSession (Also the commands used when
# creating a RestrictedRemoteServer )
$CmdsToExclude = #(
'Get-Command' , 'Out-Default' ,
'Exit-PSSession', 'Measure-Object',
'Select-Object' , 'Get-FormatData'
)
# Hide any other commandlets except the ones needed
# to create a remote session
Get-Command | Where Visibility -eq 'Public' | ForEach-Object {
if ( $_.Name -notin $CmdsToExclude ) {
$_.Visibility = 'Private'
}
}
But I want to avoid that aproach as it seems to be more of a clumsy workaround than a proper solution.