Go Premium for a chance to win a PS4. Enter to Win

x
?
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
Medium Priority
?
164 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 71

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 85

Accepted Solution

by:
oBdA earned 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses

885 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