I have created C# API (WebApp) and WebJob
with my powershell
script in it, but WebJob
don't work, because script cant import modules that needed to work correctly and throwing following error. Can somebody help me with this trouble? Only possible solution I found is through creation Azure function but it`s not included in my subscription unfortunately.
[05/16/2018 11:30:00 > d69d33: SYS INFO] Status changed to Initializing
[05/16/2018 11:30:00 > d69d33: SYS INFO] Run script '222.ps1' with script host - 'PowerShellScriptHost'
[05/16/2018 11:30:00 > d69d33: SYS INFO] Status changed to Running
[05/16/2018 11:30:00 > d69d33: ERR ] Import-Module : The specified module 'MSOnline' was not loaded because no
[05/16/2018 11:30:01 > d69d33: ERR ] valid module file was found in any module directory.
[05/16/2018 11:30:01 > d69d33: ERR ] At D:\local\Temp\jobs\triggered\TQScheduleSyncWebJob\m2gdbfxu.z4g\222.ps1:1
[05/16/2018 11:30:01 > d69d33: ERR ] char:1
[05/16/2018 11:30:01 > d69d33: ERR ] + Import-Module MSOnline
[05/16/2018 11:30:01 > d69d33: ERR ] + ~~~~~~~~~~~~~~~~~~~~~~
[05/16/2018 11:30:01 > d69d33: ERR ] + CategoryInfo : ResourceUnavailable: (MSOnline:String) [Import-M
[05/16/2018 11:30:01 > d69d33: ERR ] odule], FileNotFoundException
[05/16/2018 11:30:01 > d69d33: ERR ] + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Comm
[05/16/2018 11:30:01 > d69d33: ERR ] ands.ImportModuleCommand
[05/16/2018 11:30:01 > d69d33: ERR ]
[05/16/2018 11:30:01 > d69d33: ERR ] Import-Module : The specified module 'AzureAD' was not loaded because no valid
[05/16/2018 11:30:01 > d69d33: ERR ] module file was found in any module directory.
[05/16/2018 11:30:01 > d69d33: ERR ] At D:\local\Temp\jobs\triggered\TQScheduleSyncWebJob\m2gdbfxu.z4g\222.ps1:2
[05/16/2018 11:30:01 > d69d33: ERR ] char:1
[05/16/2018 11:30:01 > d69d33: ERR ] + Import-Module AzureAD
[05/16/2018 11:30:01 > d69d33: ERR ] + ~~~~~~~~~~~~~~~~~~~~~
[05/16/2018 11:30:01 > d69d33: ERR ] + CategoryInfo : ResourceUnavailable: (AzureAD:String) [Import-Mo
[05/16/2018 11:30:01 > d69d33: ERR ] dule], FileNotFoundException
[05/16/2018 11:30:01 > d69d33: ERR ] + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Comm
[05/16/2018 11:30:01 > d69d33: ERR ] ands.ImportModuleCommand
[05/16/2018 11:30:01 > d69d33: ERR ]
[05/16/2018 11:30:02 > d69d33: ERR ] ConvertFrom-SecureString : The data protection operation was unsuccessful.
[05/16/2018 11:30:02 > d69d33: ERR ] This may have been caused by not having the user profile loaded for the
[05/16/2018 11:30:02 > d69d33: ERR ] current thread's user context, which may be the case when the thread is
[05/16/2018 11:30:02 > d69d33: ERR ] impersonating.
[05/16/2018 11:30:02 > d69d33: ERR ] At D:\local\Temp\jobs\triggered\TQScheduleSyncWebJob\m2gdbfxu.z4g\222.ps1:7
[05/16/2018 11:30:02 > d69d33: ERR ] char:9
[05/16/2018 11:30:02 > d69d33: ERR ] + $PEnc = ConvertFrom-SecureString -SecureString $POut #??? ?????????? ...
[05/16/2018 11:30:02 > d69d33: ERR ] + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[05/16/2018 11:30:02 > d69d33: ERR ] + CategoryInfo : NotSpecified: (:) [ConvertFrom-SecureString], Cr
[05/16/2018 11:30:02 > d69d33: ERR ] yptographicException
[05/16/2018 11:30:02 > d69d33: ERR ] + FullyQualifiedErrorId : System.Security.Cryptography.CryptographicExcept
[05/16/2018 11:30:02 > d69d33: ERR ] ion,Microsoft.PowerShell.Commands.ConvertFromSecureStringCommand
[05/16/2018 11:30:02 > d69d33: ERR ]
[05/16/2018 11:30:02 > d69d33: ERR ] ConvertTo-SecureString : Cannot bind argument to parameter 'String' because it
[05/16/2018 11:30:02 > d69d33: ERR ] is null.
[05/16/2018 11:30:02 > d69d33: ERR ] At D:\local\Temp\jobs\triggered\TQScheduleSyncWebJob\m2gdbfxu.z4g\222.ps1:10
[05/16/2018 11:30:02 > d69d33: ERR ] char:16
[05/16/2018 11:30:02 > d69d33: ERR ] + $PIn = $PEnc | ConvertTo-SecureString
[05/16/2018 11:30:02 > d69d33: ERR ] + ~~~~~~~~~~~~~~~~~~~~~~
[05/16/2018 11:30:02 > d69d33: ERR ] + CategoryInfo : InvalidData: (:) [ConvertTo-SecureString], Param
[05/16/2018 11:30:02 > d69d33: ERR ] eterBindingValidationException
[05/16/2018 11:30:02 > d69d33: ERR ] + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,M
[05/16/2018 11:30:02 > d69d33: ERR ] icrosoft.PowerShell.Commands.ConvertToSecureStringCommand
[05/16/2018 11:30:02 > d69d33: ERR ]
[05/16/2018 11:30:02 > d69d33: ERR ] New-Object : Exception calling ".ctor" with "2" argument(s): "Cannot process
[05/16/2018 11:30:02 > d69d33: ERR ] argument because the value of argument "password" is null. Change the value of
[05/16/2018 11:30:02 > d69d33: ERR ] argument "password" to a non-null value."
[05/16/2018 11:30:02 > d69d33: ERR ] At D:\local\Temp\jobs\triggered\TQScheduleSyncWebJob\m2gdbfxu.z4g\222.ps1:11
[05/16/2018 11:30:02 > d69d33: ERR ] char:10
[05/16/2018 11:30:02 > d69d33: ERR ] + $Creds = New-Object System.Management.Automation.PSCredential -Argume ...
[05/16/2018 11:30:02 > d69d33: ERR ] + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[05/16/2018 11:30:02 > d69d33: ERR ] + CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvoca
[05/16/2018 11:30:02 > d69d33: ERR ] tionException
[05/16/2018 11:30:02 > d69d33: ERR ] + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.Power
[05/16/2018 11:30:02 > d69d33: ERR ] Shell.Commands.NewObjectCommand
[05/16/2018 11:30:02 > d69d33: ERR ]
[05/16/2018 11:30:04 > d69d33: ERR ] Connect-MsolService : The term 'Connect-MsolService' is not recognized as the
[05/16/2018 11:30:04 > d69d33: ERR ] name of a cmdlet, function, script file, or operable program. Check the
[05/16/2018 11:30:04 > d69d33: ERR ] spelling of the name, or if a path was included, verify that the path is
[05/16/2018 11:30:04 > d69d33: ERR ] correct and try again.
[05/16/2018 11:30:04 > d69d33: ERR ] At D:\local\Temp\jobs\triggered\TQScheduleSyncWebJob\m2gdbfxu.z4g\222.ps1:14
[05/16/2018 11:30:04 > d69d33: ERR ] char:1
[05/16/2018 11:30:04 > d69d33: ERR ] + Connect-MsolService -Credential $creds
[05/16/2018 11:30:04 > d69d33: ERR ] + ~~~~~~~~~~~~~~~~~~~
[05/16/2018 11:30:04 > d69d33: ERR ] + CategoryInfo : ObjectNotFound: (Connect-MsolService:String) [],
[05/16/2018 11:30:04 > d69d33: ERR ] CommandNotFoundException
[05/16/2018 11:30:04 > d69d33: ERR ] + FullyQualifiedErrorId : CommandNotFoundException
[05/16/2018 11:30:04 > d69d33: ERR ]
[05/16/2018 11:30:04 > d69d33: ERR ] Connect-AzureAD : The term 'Connect-AzureAD' is not recognized as the name of
[05/16/2018 11:30:04 > d69d33: ERR ] a cmdlet, function, script file, or operable program. Check the spelling of
[05/16/2018 11:30:04 > d69d33: ERR ] the name, or if a path was included, verify that the path is correct and try
[05/16/2018 11:30:04 > d69d33: ERR ] again.
[05/16/2018 11:30:04 > d69d33: ERR ] At D:\local\Temp\jobs\triggered\TQScheduleSyncWebJob\m2gdbfxu.z4g\222.ps1:15
[05/16/2018 11:30:04 > d69d33: ERR ] char:1
[05/16/2018 11:30:04 > d69d33: ERR ] + Connect-AzureAD -Credential $creds
[05/16/2018 11:30:04 > d69d33: ERR ] + ~~~~~~~~~~~~~~~
[05/16/2018 11:30:04 > d69d33: ERR ] + CategoryInfo : ObjectNotFound: (Connect-AzureAD:String) [], Com
[05/16/2018 11:30:04 > d69d33: ERR ] mandNotFoundException
[05/16/2018 11:30:04 > d69d33: ERR ] + FullyQualifiedErrorId : CommandNotFoundException
[05/16/2018 11:30:04 > d69d33: ERR ]
[05/16/2018 11:30:04 > d69d33: ERR ] Get-AzureADUser : The term 'Get-AzureADUser' is not recognized as the name of
[05/16/2018 11:30:04 > d69d33: ERR ] a cmdlet, function, script file, or operable program. Check the spelling of
[05/16/2018 11:30:04 > d69d33: ERR ] the name, or if a path was included, verify that the path is correct and try
[05/16/2018 11:30:04 > d69d33: ERR ] again.
[05/16/2018 11:30:04 > d69d33: ERR ] At D:\local\Temp\jobs\triggered\TQScheduleSyncWebJob\m2gdbfxu.z4g\222.ps1:20
[05/16/2018 11:30:04 > d69d33: ERR ] char:12
[05/16/2018 11:30:04 > d69d33: ERR ] + $kwusers = Get-AzureADUser -ObjectId 'spo.test@kwpmc.com'
[05/16/2018 11:30:04 > d69d33: ERR ] + ~~~~~~~~~~~~~~~
[05/16/2018 11:30:04 > d69d33: ERR ] + CategoryInfo : ObjectNotFound: (Get-AzureADUser:String) [], Com
[05/16/2018 11:30:04 > d69d33: ERR ] mandNotFoundException
[05/16/2018 11:30:05 > d69d33: ERR ] + FullyQualifiedErrorId : CommandNotFoundException
[05/16/2018 11:30:05 > d69d33: ERR ]
[05/16/2018 11:30:05 > d69d33: ERR ] Write-Host : The Win32 internal error "The handle is invalid" 0x6 occurred
[05/16/2018 11:30:05 > d69d33: ERR ] while setting character attributes for the console output buffer. Contact
[05/16/2018 11:30:05 > d69d33: ERR ] Microsoft Customer Support Services.
[05/16/2018 11:30:05 > d69d33: ERR ] At D:\local\Temp\jobs\triggered\TQScheduleSyncWebJob\m2gdbfxu.z4g\222.ps1:49
[05/16/2018 11:30:05 > d69d33: ERR ] char:1
[05/16/2018 11:30:05 > d69d33: ERR ] + Write-Host "?????? ????????????? ?????????"
[05/16/2018 11:30:05 > d69d33: ERR ] + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[05/16/2018 11:30:05 > d69d33: ERR ] + CategoryInfo : ResourceUnavailable: (:) [Write-Host], HostExcep
[05/16/2018 11:30:05 > d69d33: ERR ] tion
[05/16/2018 11:30:05 > d69d33: ERR ] + FullyQualifiedErrorId : SetConsoleTextAttribute,Microsoft.PowerShell.Com
[05/16/2018 11:30:05 > d69d33: ERR ] mands.WriteHostCommand
[05/16/2018 11:30:05 > d69d33: ERR ]
[05/16/2018 11:30:05 > d69d33: SYS INFO] Status changed to Success