diff --git a/WilmaPSWorker/Private/Get-CredFile.ps1 b/WilmaPSWorker/Private/Get-CredFile.ps1 index 8f97535..ce15a36 100644 --- a/WilmaPSWorker/Private/Get-CredFile.ps1 +++ b/WilmaPSWorker/Private/Get-CredFile.ps1 @@ -3,12 +3,12 @@ Converts credential to tmpfile #> function Get-CredFile(){ + [CmdletBinding()] param( [parameter(Mandatory=$true)] [pscredential] $cred ) - $pwdfile = [System.IO.Path]::GetTempFileName() $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($cred.Password) $UnsecurePassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR) diff --git a/WilmaPSWorker/Private/Get-SHA1StringHash.ps1 b/WilmaPSWorker/Private/Get-SHA1StringHash.ps1 index 8d7b314..a0fba7d 100644 --- a/WilmaPSWorker/Private/Get-SHA1StringHash.ps1 +++ b/WilmaPSWorker/Private/Get-SHA1StringHash.ps1 @@ -3,6 +3,7 @@ Builds SHA1 string for wilma login #> Function Get-SHA1StringHash() { + [CmdletBinding()] param( [Parameter(Mandatory=$true)] diff --git a/WilmaPSWorker/Private/Remove-TempFile.ps1 b/WilmaPSWorker/Private/Remove-TempFile.ps1 index 1cb3808..1e6cc9b 100644 --- a/WilmaPSWorker/Private/Remove-TempFile.ps1 +++ b/WilmaPSWorker/Private/Remove-TempFile.ps1 @@ -3,6 +3,7 @@ Overwrites or wipes temp files before removing. #> function Remove-TempFile { + [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string]$tmpfile diff --git a/WilmaPSWorker/Public/Connect-WPSWSession.ps1 b/WilmaPSWorker/Public/Connect-WPSWSession.ps1 index 57cb1ca..0871d26 100644 --- a/WilmaPSWorker/Public/Connect-WPSWSession.ps1 +++ b/WilmaPSWorker/Public/Connect-WPSWSession.ps1 @@ -26,8 +26,8 @@ function Connect-WPSWSession (){ try { Write-Verbose "Calling New-WPSWSession -site $site" $WPSWSession = New-WPSWSession -site $site - Write-Debug $WPSWSession.Result.LoginResult - $PsCmdlet.SessionState.PSVariable.Set("_WPSWSession",$WPSWSession ) + Write-Debug "Login result: $($WPSWSession.Result.LoginResult)" + Set-Variable -Name '_WPSWSession' -Value $WPSWSession -Scope Script -Force } Catch { diff --git a/WilmaPSWorker/Public/Get-WPSWCurrentSession.ps1 b/WilmaPSWorker/Public/Get-WPSWCurrentSession.ps1 index 389b473..f7543ef 100644 --- a/WilmaPSWorker/Public/Get-WPSWCurrentSession.ps1 +++ b/WilmaPSWorker/Public/Get-WPSWCurrentSession.ps1 @@ -9,13 +9,16 @@ Get-WPSWCurrentSession function Get-WPSWCurrentSession (){ [CmdletBinding()] param() - try { - Write-Verbose "Get-WPSWCurrentSession" - $WPSWSession = $PsCmdlet.SessionState.PSVariable.Get("_WPSWSession") - $WPSWSession.Value + begin { + try { + Write-Verbose "Get-WPSWCurrentSession -Begin" + $WPSWSession = Get-Variable -Name '_WPSWSession' -Scope Script + } + Catch { + Throw "Cannot get Current WPSWSession. have you set up your site settings with New-WPSWSite and Connect-WPSWSession" + } } - Catch { - Throw "Cannot get Current WPSWSession. have you set up your site settings with New-WPSWSite and Connect-WPSWSession" + process { + $WPSWSession.Value } - } diff --git a/WilmaPSWorker/Public/Get-WPSWMessage.ps1 b/WilmaPSWorker/Public/Get-WPSWMessage.ps1 index d6ddb67..72570e1 100644 --- a/WilmaPSWorker/Public/Get-WPSWMessage.ps1 +++ b/WilmaPSWorker/Public/Get-WPSWMessage.ps1 @@ -28,7 +28,14 @@ function Get-WPSWMessage (){ $Folder ) begin{ - $WPSWSession = Get-WPSWCurrentSession + Write-Verbose "Get-WPSWMessage - Begin" + try { + $WPSWSession = Get-WPSWCurrentSession + } catch { + Throw "Get-WPSWMessage - Cannot get Current WPSWSession." + } + + $urimap =@{ 'Inbox' = '/messages/index_json' 'Sent' = '/messages/index_json/outbox' @@ -39,6 +46,8 @@ function Get-WPSWMessage (){ } process { + write-verbose "Get-WPSWMessage - Session : $WPSWSession" + try { if ($Message_id){ @@ -58,7 +67,7 @@ function Get-WPSWMessage (){ } catch{ $ErrorMessage = $_.Exception.Message - Write-Error "Could get messages. $ErrorMessage" + Write-Error "Could not get messages. $ErrorMessage" } } } diff --git a/WilmaPSWorker/Public/Get-WPSWSite.ps1 b/WilmaPSWorker/Public/Get-WPSWSite.ps1 index a511c0a..c7fbff9 100644 --- a/WilmaPSWorker/Public/Get-WPSWSite.ps1 +++ b/WilmaPSWorker/Public/Get-WPSWSite.ps1 @@ -3,6 +3,7 @@ Gets all Wilma site settings or specific site settings #> function Get-WPSWSite(){ + [CmdletBinding()] param( [string]$site ) diff --git a/WilmaPSWorker/WilmaPSWorker.psm1 b/WilmaPSWorker/WilmaPSWorker.psm1 index b66fe32..9e5f2cd 100644 --- a/WilmaPSWorker/WilmaPSWorker.psm1 +++ b/WilmaPSWorker/WilmaPSWorker.psm1 @@ -5,15 +5,20 @@ Tools to interact with Visma Wilma and Primus with primusquery Collection of tools that make working with Wilma little bit easier and more secure. #> +#Current session variable + +New-Variable -Name '_WPSWSession' -Value @{} -Scope Local -Force + # Dot source public/private functions $public = @(Get-ChildItem -Path (Join-Path -Path $PSScriptRoot -ChildPath 'Public/*.ps1') -Recurse -ErrorAction Stop) $private = @(Get-ChildItem -Path (Join-Path -Path $PSScriptRoot -ChildPath 'Private/*.ps1') -Recurse -ErrorAction Stop) foreach ($import in @($public + $private)) { try { - Import-module $import.FullName + . $import.FullName } catch { throw "Unable to import-module [$($import.FullName)]" } } +