Test/initialize-knowledgearticle.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
param ( $count = 1)
BEGIN
{
    # the definition of Out-TestLog
    . ./Common.ps1
    $TESTNAME = $MyInvocation.MyCommand
    $DOCUMENT = "${PWD}\Document.RTF"
    $class = get-scsmclass "System.Knowledge.Article"
    # get rid of the article we're creating
    get-scsmobject -class $class -filter "DisplayName = 'TestArticle1'"|
        remove-scsmobject -force
    $STARTTIME = [datetime]::Now
    $OPEN = ([io.filemode]::Open)
    $RACC = ([io.fileaccess]::Read)
    $RSHR = ([io.fileshare]::read)
}
END
{


    for($i = 0; $i -lt $count; $i++)
    {
        try
        {
            $G = [guid]::NewGuid()
            $script:str = new-object io.filestream "${DOCUMENT}",$OPEN,$RACC,$RSHR
            new-scsmobject -class $class -PropertyHashtable @{ 
                ArticleID = "TestArticle: ${G}"
                Title = "KB ${G}"
                Status = "Draft" 
                EndUserContent = $str
                }
        }
        catch 
        {
            Write-Host -for red $error
        }
        finally
        {
            $str.close()
            $str.dispose()
        }
    }

}