DataGen/Common.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608

$ACTIVITYHASREVIEWERRELATIONSHIP   = Get-SCSMRelationshipClass System.ReviewActivityHasReviewer
$REVIEWERISUSERRELATIONSHIP        = Get-SCSMRelationshipClass System.ReviewerIsUser
$WORKITEMCREATEDBYUSERRELATIONSHIP = Get-SCSMRelationshipClass System.WorkitemCreatedByUser
$ASSIGNEDTOUSERRELATIONSHIP        = Get-SCSMRelationshipClass System.WorkItemAssignedToUser
$REVIEWERISUSERRELATIONSHIP        = Get-SCSMRelationshipClass System.ReviewerIsUser

$RANDOM = new-object System.Random

function Get-RandomVersion
{
    new-object System.Version ("{0}.{1}.{2}.{3}" -f $RANDOM.Next(1,8),$RANDOM.Next(0,15),$RANDOM.Next(20,100),$RANDOM.Next(20,100))
}
function get-RandomIPAddress
{
    BEGIN
    {
    $b = new-object byte[] 4
    }
    PROCESS
    {
    $RANDOM.NextBytes($b)
    "{0}.{1}.{2}.{3}" -f $b[0],$b[1],$b[2],$b[3]
    }
}

function new-SN
{
    BEGIN
    {
        $a1a = 1000; $a1b = 9999
        $a2a = 10; $a2b = 99
        $R = new-object System.Random
    }
    PROCESS
    {
        "{0}-{1}-{2}-{3}-{4}-{5}-{6}-{7}" -f $R.Next($a1a,$a1b),$R.Next($a1a,$a1b),$R.next($a1a,$a1b),$R.next($a1a,$a1b),$R.next($a1a,$a1b),$R.next($a1a,$a1b),$R.next($a1a,$a1b),$R.next($a2a,$a2b)
    }
}

function get-phone
{
    param ( [string]$prefix, $count = 1)
    BEGIN
    {
        $l = 10
        $pn = new-object int[] $l
        if ( $prefix )
        {
            $prefix = $prefix -replace "-"
            $l -= ([string]$prefix).Length
        }
        $byte = new-object byte[] $l
        ([int[]][string[]]("$prefix".ToCharArray())).CopyTo($pn,0)
    }
    PROCESS
    {
        $current = 0
        while($current++ -lt $count)
        {
            $random.NextBytes($byte)
            $nn = ($byte|%{[int][string]("$_"[-1])})
            @($nn).CopyTo($pn,10-$l)
            $pn = $pn|%{$_}
            "{0}{1}{2}-{3}{4}{5}-{6}{7}{8}{9}" -f $pn
        }
    }
}

function new-FileAttachmentStream
{
    param ( $count = 3 )
    $OPEN = ([io.filemode]::Open)
    $RACC = ([io.fileaccess]::Read)
    $RSHR = ([io.fileshare]::read)
    for($i = 0; $i -lt $count; $i++)
    {
        $DOCUMENT = [io.path]::GetTempFileName()
        get-lorem 60 > $DOCUMENT
        new-object io.filestream $DOCUMENT,$OPEN,$RACC,$RSHR
    }
}

function Get-LogicalDisk
{
    param ( $PrincipalName )
    if ( @($__ldisks)[0] -isnot [System.Management.ManagementObject] )
    {
        $script:__ldisks = get-wmiobject win32_logicaldisk
    }
    $__ldisks | %{
        @{
            AssetStatus                  = "Deployed"
            Compressed                   = $_.Compressed
            Description                  = $_.Description
            DeviceID                     = $_.DeviceId
            DriveType                    = $_.DriveType
            FileSystem                   = $_.FileSystem
            FreeSpace                    = [int]($_.FreeSpace/1mb)
            Name                         = $_.Name
            Notes                        = get-lorem 12
            PrincipalName                = $PrincipalName
            QuotasDisabled               = $_.QuotasDisabled
            Size                         = [int]($_.Size/1mb)
            SupportsDiskQuota            = $_.SupportsDiskQuotas
            SupportsFileBasedCompression = $_.SupportsFileBasedCompression
            VolumeName                   = $_.VolumeSerialNumber
        }
    }
}

function Get-ComputerSystem
{
    param ( $PrincipalName )
    
    if ( @($__csystem)[0] -isnot [System.Management.ManagementObject] )
    {
        $script:__csystem = get-wmiobject win32_ComputerSystem
    }
    $__csystem | %{
        @{
            DisplayName        = $PrincipalName
            HardwareId         = [guid]::NewGuid().ToString()
            Manufacturer       = $_.Manufacturer
            Model              = $_.Model
            Notes              = get-lorem 6
            NumberOfProcessors = $_.NumberOfProcessors
            PlatformType       = $_.Description
            SerialNumber       = new-SN
            SMBIOS_UUID        = new-SN
            SMBIOSAssetTag     = new-SN
        }
    }
}
function Get-PhysicalDisk
{
    param ( $PrincipalName )
    
    if ( @($__pdisks)[0] -isnot [System.Management.ManagementObject] )
    {
        $script:__pdisks = get-wmiobject win32_diskdrive
    }
    $__pdisks | %{
        $totalSectors = $_.TotalSectors
        if ( $totalSectors -gt [int]::MaxValue ) { $totalSectors = [int]::MaxValue }
        @{
            AssetStatus        = "Deployed"
            Caption            = $_.Caption
            Description        = $_.Description
            DeviceID           = $_.DeviceId
            Index              = $_.Index
            InterfaceType      = $_.InterfaceType
            Manufacturer       = $_.Manufacturer
            MediaType          = $_.MediaType
            Model              = $_.Model
            Name               = $_.Name
            Notes              = Get-Lorem 12
            PNPDeviceId        = $_.PNPDeviceId
            PrincipalName      = $PrincipalName
            SCSIBus            = $_.SCSIBus
            SCSILogicalUnit    = $_.SCSILogicalUnit
            SCSIPort           = $_.SCSIPort
            SCSITargetID       = $_.SCSITargetId
            Size               = [int]($_.Size/1mb)
            TotalCylinders     = $_.TotalCylnders
            TotalHeads         = $_.TotalHeads
            TotalSectors       = $TotalSectors
            TotalTracks        = $_.TotalTracks
            TracksPerCylinder  = $_.TracksPerCylinder
            }
        }
}
function Get-Partition
{
    param ( $PrincipalName )
    if ( @($__part)[0] -isnot [System.Management.ManagementObject] )
    {
        $script:__part = get-wmiobject win32_diskpartition
    }
    $__part | %{
        @{
            BlockSize        = $_.BlockSize
            Bootable         = $_.Bootable
            Description      = $_.Description
            DeviceID         = $_.DeviceId
            DiskIndex        = $_.DiskIndex
            DisplayName      = $_.Caption
            Name             = $_.Caption
            Notes            = Get-Lorem 12
            PrimaryPartition = $_.PrimaryPartition
            PrincipalName    = $PrincipalName
            Size             = [int]($_.Size/1MB)
            Type             = $_.Type
        }
    }
}
function Get-Processor
{
    param ( $PrincipalName )
    # this should be SMS_Processor, but that may not be present
    # unless configuration manager client is installed
    # this will do the best it can
    if ( @($__Processors)[0] -isnot [System.Management.ManagementObject] )
    {
        $script:__Processors = get-wmiobject Win32_Processor 
    }
    $__Processors | %{
        $Processor = $_
        @{
            AssetStatus     = "Deployed"
            # BrandId =
            # CPUKey =
            DataWidth       = $Processor.DataWidth
            Description     = $Processor.Description
            DeviceID        = $Processor.DeviceID
            Family          = $Processor.Family
            # IsMobile = $Processor.
            IsMulticore     = &{ if ( $Processor.NumberofCores -gt 1 ) { $true } else { $false } }
            Manufacturer    = $Processor.Manufacturer
            MaxClockSpeed   = $Processor.MaxClockSpeed
            Name            = $Processor.Name
            Notes           = get-lorem 12
            # PCache = $Processor.
            PrincipalName   = $PrincipalName
            Revision        = $Processor.Revision
            Speed           = $Processor.CurrentClockSpeed
            Type            = $Processor.ProcessorType
            Version         = $Processor.Version
        } 
    }
}
function Get-NetworkAdapter
{
    param ( $PrincipalName )
    if ( @($__NAConf)[0] -isnot [System.Management.ManagementObject] )
    {
        #write-host -for red "get network conf"
        $script:__NAConf = get-wmiobject Win32_NetworkAdapterConfiguration 
    }
    if ( @($__NA)[0] -isnot [System.Management.ManagementObject])
    {
        #write-host -for red "get network adapt"
        $script:__NA = get-wmiobject win32_networkadapter
    }
    $__NAConf | %{
        $Config = $_
        $Index = $Config.Index
        $Adapt = $__NA | ?{$_.Index -eq $Index }
        if ( ! $Adapt ) { throw "whoops"  }
        # $Adapt = get-wmiobject win32_networkadapter -filter "Index = '$Index'"
        @{
            AdapterType        = $Adapt.AdapterType
            AssetStatus        = "Deployed"
            DefaultIPGateway   = @($Config.DefaultIPGateway) -join ", "
            Description        = $Config.Description
            DeviceID           = $Adapt.DeviceId
            DHCPEnabled        = $Config.DHCPEnabled
            DHCPServer         = $Config.DHCPServer
            DNSDomain          = $Config.DNSDomain
            Index              = $Index
            IPAddress          = @($Config.IPAddress) -join ", "
            IPEnabled          = $Config.IPEnabled
            IPSubnet           = @($Config.IPSubnet) -join ", "
            MACAddress         = $Config.MACAddress
            Manufacturer       = $Adapt.Manufacturer
            MaxSpeed           = $Adapt.MaxSpeed
            Name               = $Adapt.Name
            Notes              = get-lorem 12
            PrincipalName      = $PrincipalName
            ProductName        = $Adapt.ProductName
            ServiceName        = $Config.ServiceName
        }
    }
}
function Get-OperatingSystem
{
    param ( $PrincipalName )
    if ( @($__CS)[0] -isnot [System.Management.ManagementObject] )
    {
        $script:__CS = @(get-wmiobject win32_computersystem)[0]
    }
    if ( @($__OS)[0] -isnot [System.Management.ManagementObject] )
    {
        $script:__OS = @(get-wmiobject win32_OperatingSystem)[0]
    }
    @{
        DisplayName           = $__OS.Caption
        AssetStatus           = "Deployed"
        BuildNumber           = $__OS.BuildNumber
        CountryCode           = $__OS.CountryCode
        CSDVersion            = $__OS.CSDVersion
        Description           = $__OS.Description
        InstallDate           = $__OS.InstallDate
        Locale                = $__OS.Location
        LogicalProcessors     = $__CS.NumberOfLogicalProcessors
        MajorVersion          = ([version]($__OS.Version)).Major
        Manufacturer          = $__OS.Manufacturer
        MinorVersion          = ([version]($__OS.Version)).Minor
        Notes                 = get-lorem 12
        OSLanguage            = $__OS.OSLanguage
        OSVersion             = $__OS.Version
        OSVersionDisplayName  = $__OS.Caption
        PhysicalMemory        = [int]($__CS.TotalPhysicalMemory/1mb)
        PrincipalName         = $PrincipalName
        ProductType           = $__OS.ProductType
        SerialNumber          = $__OS.SerialNumberb
        ServicePackVersion    = "{0}.{1}" -f $__OS.ServicePackMajorVersion,$__OS
        SystemDrive           = $__OS.SystemDrive
        WindowsDirectory      = $__OS.WindowsDirectory
    }
}

function Get-Priority
{
    param ( [string]$myurgency, [string]$myimpact )
    $hunt = "${myurgency}${myimpact}"
    $PriorityData = (get-scsmobject (get-scsmclass System.WorkItem.Incident.GeneralSetting)).PriorityMatrix
    if ( $PriorityData )
    {
        $matrix = [xml]$PriorityData
    }
    $Impact  = Get-SCSMEnumeration System.WorkItem.TroubleTicket.ImpactEnum.|sort-object Ordinal
    $Urgency = Get-SCSMEnumeration System.WorkItem.TroubleTicket.UrgencyEnum.|sort-object Ordinal
    $hash = @{}
    $count=1
    foreach($U in $Urgency)
    {
        foreach($I in $Impact)
        {
            $UN = $U.DisplayName; $IN = $I.DisplayName
            $UID = $U.ID; $IID = $I.ID
            $xpath = "Matrix/U[@Id='$UID']/I[@Id='$IID']/P"
            if ( $ProrityData )
            {
                $value = $Matrix.SelectSingleNode($xpath)."#text"
            }
            else
            {
                $Value = $count++
            }
            $hash["${UN}${IN}"] = $value
        }
    }
    $hash[$hunt]
}

function Get-State
{
$States = "AL","AK","AS","AZ","AR","CA","CO","CT","DE","DC","FM","FL","GA","GU","HI","ID","IL","IN",
          "IA","KS","KY","LA","ME","MH","MD","MA","MI","MN","MS","MO","MT","NE","NV","NH","NJ","NM",
          "NY","NC","ND","MP","OH","OK","OR","PW","PA","PR","RI","SC","SD","TN","TX","UT","VT","VI",
          "VA","WA","WV","WI","WY"
Get-RandomItemFromList $States
}
function Get-RandomItemFromList
{
param ( [Parameter(Mandatory=$true,Position=0)]$list, [Parameter(Position=1)]$favoredItem )
    if ( $favoredItem -and ($random.next(0,3) -eq 1))
    {
        $favoredItem
    }
    else
    {
        $list[$RANDOM.Next(0,$list.Count)]
    }
}

function Get-RandomListFromList
{
param ( 
    [Parameter(Mandatory=$true,Position=0)]$list, 
    [Parameter(Mandatory=$true,Position=1)][int]$count
    )
$mylist = [Collections.ArrayList]$list
$RandomList =  @()
for($i = 0; $i -lt $count -and $mylist.Count -gt 0; $i++)
{
    $r = $RANDOM.Next(0,$mylist.Count)
    $RandomList += $mylist[$r]
    $mylist.RemoveAt($r)
}
$RandomList
}

function Get-Lorem
{
    param ( [int]$count = 11, [switch]$Start, [int]$length, [switch]$word, [switch]$sentence, [int]$scount = 1)
    #$s = $Start.ToString().ToLower()
    #$URL = �"http://www.lipsum.com/feed/xml?amount=${count}&what=words&start=${s}"
    #[xml]$x = ((new-object net.webclient).downloadstring($URL))
    #$x.feed.lipsum
    $words = "consetetur", "sadipscing", "elitr", "sed", "diam", "nonumy", "eirmod",
        "tempor", "invidunt", "ut", "labore", "et", "dolore", "magna", "aliquyam", "erat", "sed", "diam", "voluptua",
        "at", "vero", "eos", "et", "accusam", "et", "justo", "duo", "dolores", "et", "ea", "rebum", "stet", "clita",
        "kasd", "gubergren", "no", "sea", "takimata", "sanctus", "est", "lorem", "ipsum", "dolor", "sit", "amet",
        "lorem", "ipsum", "dolor", "sit", "amet", "consetetur", "sadipscing", "elitr", "sed", "diam", "nonumy", "eirmod",
        "tempor", "invidunt", "ut", "labore", "et", "dolore", "magna", "aliquyam", "erat", "sed", "diam", "voluptua",
        "at", "vero", "eos", "et", "accusam", "et", "justo", "duo", "dolores", "et", "ea", "rebum", "stet", "clita",
        "kasd", "gubergren", "no", "sea", "takimata", "sanctus", "est", "lorem", "ipsum", "dolor", "sit", "amet",
        "lorem", "ipsum", "dolor", "sit", "amet", "consetetur", "sadipscing", "elitr", "sed", "diam", "nonumy", "eirmod",
        "tempor", "invidunt", "ut", "labore", "et", "dolore", "magna", "aliquyam", "erat", "sed", "diam", "voluptua",
        "at", "vero", "eos", "et", "accusam", "et", "justo", "duo", "dolores", "et", "ea", "rebum", "stet", "clita",
        "kasd", "gubergren", "no", "sea", "takimata", "sanctus", "est", "lorem", "ipsum", "dolor", "sit", "amet", "duis",
        "autem", "vel", "eum", "iriure", "dolor", "in", "hendrerit", "in", "vulputate", "velit", "esse", "molestie",
        "consequat", "vel", "illum", "dolore", "eu", "feugiat", "nulla", "facilisis", "at", "vero", "eros", "et",
        "accumsan", "et", "iusto", "odio", "dignissim", "qui", "blandit", "praesent", "luptatum", "zzril", "delenit",
        "augue", "duis", "dolore", "te", "feugait", "nulla", "facilisi", "lorem", "ipsum", "dolor", "sit", "amet",
        "consectetuer", "adipiscing", "elit", "sed", "diam", "nonummy", "nibh", "euismod", "tincidunt", "ut", "laoreet",
        "dolore", "magna", "aliquam", "erat", "volutpat", "ut", "wisi", "enim", "ad", "minim", "veniam", "quis",
        "nostrud", "exerci", "tation", "ullamcorper", "suscipit", "lobortis", "nisl", "ut", "aliquip", "ex", "ea",
        "commodo", "consequat", "duis", "autem", "vel", "eum", "iriure", "dolor", "in", "hendrerit", "in", "vulputate",
        "velit", "esse", "molestie", "consequat", "vel", "illum", "dolore", "eu", "feugiat", "nulla", "facilisis", "at",
        "vero", "eros", "et", "accumsan", "et", "iusto", "odio", "dignissim", "qui", "blandit", "praesent", "luptatum",
        "zzril", "delenit", "augue", "duis", "dolore", "te", "feugait", "nulla", "facilisi", "nam", "liber", "tempor",
        "cum", "soluta", "nobis", "eleifend", "option", "congue", "nihil", "imperdiet", "doming", "id", "quod", "mazim",
        "placerat", "facer", "possim", "assum", "lorem", "ipsum", "dolor", "sit", "amet", "consectetuer", "adipiscing",
        "elit", "sed", "diam", "nonummy", "nibh", "euismod", "tincidunt", "ut", "laoreet", "dolore", "magna", "aliquam",
        "erat", "volutpat", "ut", "wisi", "enim", "ad", "minim", "veniam", "quis", "nostrud", "exerci", "tation",
        "ullamcorper", "suscipit", "lobortis", "nisl", "ut", "aliquip", "ex", "ea", "commodo", "consequat", "duis",
        "autem", "vel", "eum", "iriure", "dolor", "in", "hendrerit", "in", "vulputate", "velit", "esse", "molestie",
        "consequat", "vel", "illum", "dolore", "eu", "feugiat", "nulla", "facilisis", "at", "vero", "eos", "et", "accusam",
        "et", "justo", "duo", "dolores", "et", "ea", "rebum", "stet", "clita", "kasd", "gubergren", "no", "sea",
        "takimata", "sanctus", "est", "lorem", "ipsum", "dolor", "sit", "amet", "lorem", "ipsum", "dolor", "sit",
        "amet", "consetetur", "sadipscing", "elitr", "sed", "diam", "nonumy", "eirmod", "tempor", "invidunt", "ut",
        "labore", "et", "dolore", "magna", "aliquyam", "erat", "sed", "diam", "voluptua", "at", "vero", "eos", "et",
        "accusam", "et", "justo", "duo", "dolores", "et", "ea", "rebum", "stet", "clita", "kasd", "gubergren", "no",
        "sea", "takimata", "sanctus", "est", "lorem", "ipsum", "dolor", "sit", "amet", "lorem", "ipsum", "dolor", "sit",
        "amet", "consetetur", "sadipscing", "elitr", "at", "accusam", "aliquyam", "diam", "diam", "dolore", "dolores",
        "duo", "eirmod", "eos", "erat", "et", "nonumy", "sed", "tempor", "et", "et", "invidunt", "justo", "labore",
        "stet", "clita", "ea", "et", "gubergren", "kasd", "magna", "no", "rebum", "sanctus", "sea", "sed", "takimata",
        "ut", "vero", "voluptua", "est", "lorem", "ipsum", "dolor", "sit", "amet", "lorem", "ipsum", "dolor", "sit",
        "amet", "consetetur", "sadipscing", "elitr", "sed", "diam", "nonumy", "eirmod", "tempor", "invidunt", "ut",
        "labore", "et", "dolore", "magna", "aliquyam", "erat", "consetetur", "sadipscing", "elitr", "sed", "diam",
        "nonumy", "eirmod", "tempor", "invidunt", "ut", "labore", "et", "dolore", "magna", "aliquyam", "erat", "sed",
        "diam", "voluptua", "at", "vero", "eos", "et", "accusam", "et", "justo", "duo", "dolores", "et", "ea",
        "rebum", "stet", "clita", "kasd", "gubergren", "no", "sea", "takimata", "sanctus", "est", "lorem", "ipsum" 
     
    $random = new-object System.Random
    if ( $word )
    {
        start-sleep -mil 15
        $w = $words[$random.Next($words.length-1)]
        [char]::ToUpper($w[0]) + $w.substring(1)
        return
    }
    if ( $Start ) 
    { 
        $string = "lorem ipsum dolor sit amet "
        $total = $count - 5
    }
    else
    {
        $total = $count
    }
    if ( $length )
    {
        #write-host -for red "Calling for: $length"
        $nextword = $words[$random.Next($words.length - 1)] + " "
        while ( ($string.length + $nextword.length) -lt $length )
        {
            $string += $nextword
            $nextword = $words[$random.Next($words.length - 1)] + " "
        }
    }
    else
    {
    $NeedCap = $true
    1..$total | %{ $currentCount = 0; [int]$slen = $total / $scount } {
            $nextword = $words[$random.Next($words.length - 1)]
            if ( $NeedCap )
            {
                $nextword = [Globalization.CultureInfo]::CurrentCulture.TextInfo.ToTitleCase($nextword)
            }
            $string += $nextword
            $addDot = ++$currentCount % $slen
            if ( ($scount -ne 1) -and ( $addDot -eq 0)) 
            { 
                $string += ". " 
                $NeedCap = $true
            }
            else 
            { 
                $string += " " 
                $NeedCap = $false
            }
        } 
    }
    $string = ${string}.trim()
    if ( $sentence ) { $string += "." }
    [char]::ToUpper($string[0]) + $string.Substring(1)
}

function Get-InstanceHash
{
param ( 
    [parameter(Mandatory=$true)]$id,
    [parameter(Mandatory=$false)][int]$sequence,
    [parameter(Mandatory=$false)]$stage, 
    [parameter(Mandatory=$false)]$status 
    )
$h = @{
    Id = $id
    Title = get-lorem 5
    Description = Get-Lorem 24
}
if ( $sequence ) { $h['SequenceId'] = $sequence }
if ( $stage )    { $h['Stage']      = $stage    }
if ( $status )   { $h['Status']     = $status   }
$h
}

# build an instance on the fly
function new-instance
{
    param ( $Name , $class, [switch]$commit, [switch]$objectonly)
    if ( ! $class )
    {
        $class = get-scsmclass "^${name}$"
    }

    if (! $class ) { throw Could not find class }

    $RANDOM = new-object random
    $properties = $class | get-smproperty
    $hash = @{}
    foreach($property in $properties )
    {
        $name = $property.Name
        if ( $name -eq "DisplayName") { continue }
        switch -exact ( $property.type )
        {
            "richtext"  {

                break;
                }
            "String"   { 
                if ( $property.AutoIncrement )
                {
                    $hash[$name] = "${classname}{0}"
                }
                elseif ( $property.Key )
                {
                    $hash[$name] = [guid]::NewGuid().ToString()
                }
                else
                {
                    $min = $property.Minlength
                    if ( $Min -lt 10 ) { $min = 10 }
                    $hash[$name] = get-lorem -length ($RANDOM.Next($Min, $property.MaxLength))
                }
                break 
                }
            "datetime" { 
                $hash[$name] = [datetime]::Now.AddHours($RANDOM.NEXT(-180,-90))
                break 
                }
            "guid" {
                $hash[$name] = [guid]::NewGuid()
                break
                }
            "bool"  { 
                $hash[$name] = [bool]$RANDOM.Next(0,2)
                break 
                }
            "int" {
                $hash[$name] = $RANDOM.Next($property.MinValue,$property.MaxValue)
                break
                }
            "double" {
                $hash[$name] = $RANDOM.Next(-1mb,1mb)/1001.1
                break
                }
            "binary" {
                # this is usually a file handle - for our purposes, we'll not bother
                # $hash[$name] = $RANDOM.Next(-1mb,1mb)/1001.1
                if ( $property.Required -or $property.Key )
                {
                    throw "no data available for binary type"
                }
                break
                }
            default    {
                if ( $property.SystemType -match "Enum" )
                {
                    $elist = get-scsmchildenumeration -en (get-scsmenumeration -id $property.EnumType.id)
                    $hash[$property.name] = $elist[$RANDOM.NEXT(0,$elist.count)]
                }
                else
                {
                    write-host -for yellow $property.type not handled
                }
            }
        }
    }
    if ( $commit )
    {
        new-scsmobject -class $class $hash
    }
    if ( $objectonly )
    {
        new-scsmobject -class $class $hash -nocommit
    }
    else
    {
        $hash
    }
}