Solved

Error Cannot find the type for custom attribute 'CmdletBidning'. Make sure that the assembly that contains this type is loaded.

Posted on 2016-11-20
4
60 Views
Last Modified: 2016-12-21
Hello,
I am learning powershell and doing this exercise by following some training videos. But it gives me this error. Why? Googled it and it didn't help me to resolve it.

 Cannot find the type for custom attribute 'CmdletBidning'. Make sure that the assembly that contains this type is loaded.


function CFCompINfo
{
    [CmdletBinding()]
    [Alias(hostname)]
    [OutputType([int])]
    [string[]$CommputerName
    [switch]$nameLog
    Param
    (
        # Param1 help description
        [Parameter(Mandatory=$true,
                    ValueFromPipeline=$true,
                   ValueFromPipelineByPropertyName=$true,
                   Position=0)]
       [string[] $Computername,
       [switch]$nameLog

       
    )

   BEgin {}
Process {
    foreach ($computer in $computername)
{
write-host $computer    
}

}

End {}


}

Get-DJOSInfo -computername my-pc
#Get-DJOSInfo -computername dc1, dc2
#Get-DJOSInfo computers.txt | Get-DJOSInfo -namelog
#Get-DJOSInfo -host localhost
0
Comment
Question by:creative555
  • 2
4 Comments
 
LVL 69

Expert Comment

by:Qlemo
ID: 41895112
All parts before the param belong inside the {b]param[/b].
0
 

Author Comment

by:creative555
ID: 41895231
hm. THey are in inside {......Besides I also tried inserting snippet from Powershell and everying seems to be fine but still getting the error.
Could you please give an example how it should be. L


Function Get-DJOSInfo {
[CmdletBidning()]
    param([Parameter(Mandatory=$true,
    ValueFromPipeline=$true,
    ValueFromPipelineByPropertyName=$true)]
    [Alias('hostname')]
    [string[]$CommputerName,
    [switch]$nameLog
)
BEgin {}
Process {
    foreach ($computer in $computername)
{
#write-host $computer  
    $os = get-wmiobject -computerName $Computer -class Win32_OperatingSystem | select Caption,Build,OSARchitecture,ServicePackMajorVErsion
    $bios = get-wmiObject -computerName $Computer -class Win32_BIOS | select SerialNumber
    $processor = get-WMIObject -computerName $Computer -class Win32_Processor | select AddressWidth -first 1
}

}

End {}


}
0
 
LVL 84

Accepted Solution

by:
oBdA earned 500 total points
ID: 41895409
* It's "CmdletBinding", not "CmdletBidning"
* "[string[]$ComputerName" is missing a closing square bracket: "[string[]]$ComputerName",
* In the Param section, you had "$CommputerName" instead of "$ComputerName"
* The function is generating no pipeline output.
* Convention for Powershell scripts is Pascal Case, see "Strongly Encouraged Development Guidelines", https://msdn.microsoft.com/en-us/library/dd878270(v=vs.85).aspx
It's best to get used to it form the very beginning (and so is consistent indentation).
* Using Aliases is fine in the Powershell prompt, but in scripts, you should always use the full names - you'll never know when they might be running on a machine where somebody redefined an alias (somebody might for example consider "dir" a good abbreviation for "Delete Immediate Recursive" ...)
Function Get-DJOSInfo {
[CmdletBinding()]
Param(
	[Parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]
	[Alias('hostname')]
	[string[]]$ComputerName,
	[switch]$NameLog
)
	Begin {}
	Process {
		ForEach ($Computer in $ComputerName) {
			#Write-Host $Computer
			$OS = Get-WmiObject -ComputerName $Computer -Class Win32_OperatingSystem | Select-Object Caption, Build, OSArchitecture, ServicePackMajorVersion
			$Bios = Get-WmiObject -ComputerName $Computer -Class Win32_BIOS | Select-Object SerialNumber
			$Processor = Get-WmiObject -ComputerName $Computer -Class Win32_Processor | Select-Object AddressWidth -First 1
			Write-Host "---- OS ----" -Fore Yellow
			$OS
			Write-Host "---- Bios ----" -Fore Yellow
			$Bios.SerialNumber
			Write-Host "---- Processor ----" -Fore Yellow
			$Processor.AddressWidth
		}
	}
	End {}
}

Get-DJOSInfo -ComputerName $ENV:ComputerName

Open in new window

0
 

Author Closing Comment

by:creative555
ID: 41902724
Yes!!  It's "CmdletBinding", not "CmdletBidning" Thank you!
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
home folder path for users 4 87
Batch FIle delete files with particular date 10 99
Need to learn promise API 2 55
Rename all files in a directory to numerical order 26 30
It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question