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
56 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 83

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!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

831 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