Public/New-CAMVendor.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
Function New-CAMVendor
{
<#
    .SYNOPSIS
        Function to create a new Cireson Asset Management Vendor
     
    .DESCRIPTION
        Function to create a new Cireson Asset Management Vendor
     
    .PARAMETER Name
        Specify the name of the Vendor(s)
     
    .EXAMPLE
        PS C:\> New-CAMVendor -Name "VMware"
     
    .EXAMPLE
        PS C:\> New-CAMVendor -Name "VMware", "Microsoft", "Google"
     
    .EXAMPLE
        Get-Content Vendors.txt | New-CAMVendor
         
    .EXAMPLE
        $props = @{
            Name = "Google"
            Website = "www.Google.com"
            VendorAddress1 = "San Francisco"
        }
         
        New-CAMVendor -hashtable $props
     
    .NOTES
        Francois-Xavier Cat
        lazywinadmin.com
        @lazywinadm
        github.com/lazywinadmin
#>

    [CmdletBinding(SupportsShouldProcess=$true,DefaultParameterSetName='Name')]
    PARAM (
        [Parameter(Mandatory,ValueFromPipeline,ParameterSetName='Name')]
        [String[]]$Name,
        [Parameter(Mandatory,ParameterSetName='Name')]
        [Hashtable]$HashTable
    )
    
    FOREACH ($Item in $Name)
    {
        TRY
        {
            IF ($PSBoundParameters['Name'])
            {
            
                # Define the Properties
                $properties = @{
                    Name = $Item
                }
            }
            
            IF ($PSBoundParameters['Hashtable'])
            {
                $properties = $HashTable
            }
            
            if ($PSCmdlet.ShouldProcess($properties,"Create an object of Type (Cireson.AssetManagement.Vendor)"))
            {
                # Create the Item
                New-SCSMObject -Class (get-scsmclass -name 'Cireson.AssetManagement.Vendor') -PropertyHashtable $properties
            }
        }
        CATCH
        {
            
            Write-Error -Message "[PROCESS] An Error occured"
            $Error[0].Exception.Message
        }
    }
}

#get-scsmobject -class (get-scsmclass -name 'Cireson.AssetManagement.Vendor') | fl *
#(get-scsmobject -class (get-scsmclass -name 'Cireson.AssetManagement.Vendor')).values

<#
EXAMPLE OF OUTUT
 
Name : VMWare
VendorAddress1 : Parnel House, Barrack Square
VendorAddress2 : Main St
VendorCity : Ballincollig
VendorState : Co, Cork
VendorPostCode :
VendorCountry : Ireland
VendorContact : Lauren
VendorEmail : r@wmware.com
VendorPhone : +
VendorFax :
WebSite : www.vmware.com
ObjectStatus : Active
AssetStatus :
Notes :
DisplayName : VMWare
ClassName : Cireson.AssetManagement.Vendor
LastModified : 8/3/2015 2:18:21 PM
TypeName : Cireson.AssetManagement.Vendor
Path :
FullName : Cireson.AssetManagement.Vendor:VMWare
ManagementPackClassIds : {f26c94f2-1045-3d60-4c1f-59b8cbfe9931}
LeastDerivedNonAbstractManagementPackClassId : f26c94f2-1045-3d60-4c1f-59b8cbfe9931
TimeAdded : 8/3/2015 6:18:21 PM
LastModifiedBy : 7431e155-3d9e-4724-895e-c03ba951a352
Values : {VMWare, Parnel House, Barrack Square, Main St, Ballincollig...}
IsNew : False
HasChanges : False
Id : d85104a5-bc3a-f629-84ef-15f41d21a798
ManagementGroup : SCSM WB Games Montreal
ManagementGroupId : 0ddb97c1-4a81-3958-ad92-26cb0457c075
GroupsAsDifferentType : False
ViewName : ManagedEntityGenericView
ObjectMode : All
 
#>