I wrote a script to export rows from a SQL DB, encrypt them using PGP, then transfer them using POSH-SSH v2.3.0. It all works fine, until I put it in a PowerShell WorkFlow to run multiple at a time.
This particular line is the issue:
Set-SFTPFile -SessionId $sftp.SessionId -LocalFile "$encrypted\$($file.Name).pgp" -RemotePath ".\path"
When running that line, I am getting the below error. If I comment out that line, the error goes away and the script runs fine (minus actually transferring the file).
Microsoft.PowerShell.Utility\Write-Error : Object reference not set to an instance of an object.
At StartExport:20 char:20
+
+ CategoryInfo : NotSpecified: (:) [Write-Error], RemoteException
+ FullyQualifiedErrorId : System.Management.Automation.RemoteException,Microsoft.PowerShell.Commands.WriteErrorCommand
+ PSComputerName : [localhost]
To me, it looks like there is something with POSH-SSH that is not compatible with PowerShell WorkFlows. Has anyone had any experience with this? I would try to upgrade to v3.0 PSH-SSH, but it is on a pretty locked down server that runs a lot of automation, and it would require me to install a new .NET, which could break many things.
Edit: As a test, I installed POSH-SSH v 2.3.0 on my laptop, got the same error. Then I updated POSH-SSH to version 3.0.0 (the latest) and I still get the same error.
Appreciate any help! I've been stuck on this one for quite a while.
"Module was not written to work in workflows. They are not supported at this time."
-https://github.com/darkoperator/Posh-SSH/issues/173
Not the answer I was hoping for, but now I understand. Still open to any work arounds though.
Related
Afternoon everyone. I'm running into an issue I'm not sure how to handle. I'm working on a script for work to deploy a Domain Controller using PSremoting. It all works well in fine until I get to where I'm importing some GPOs from backups.
*All the commands are run under invoke-command
I run the command Import-GPO -BackUpName $GPO -TargetName $GPO -Path $GPOPath -MigrationTable $MigTable -CreateIfNeeded
When I run this, I get an error on the host:
Operation is not valid due to the current state of the object.
+ CategoryInfo : NotSpecified: (:) [Import-GPO], InvalidOperationException
+ FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.GroupPolicy.Commands.ImportGpoCommand
+ PSComputerName : v204-DC1
I can't seem to find anything that says what this means. When I check for the GPOs on the DC, they all show up and seem to be linked properly. I am curious what this error is, or if I should just append -ErrorAction SilentlyContinue to the end of my code.
Ended up being an issue with my migration table. I rolled back to an earlier one and ended up being good to go
I have a PowerShell script which checks the currently signed in user as part of its start-up process. I'm using .Net to do this by adding the assembly:
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
$cUser = [System.DirectoryServices.AccountManagement.UserPrincipal]::Current
For almost everyone this works fine and I get a UserPrincipal object that I can use elsewhere, however there are a couple of users who get the following error when running it:
Unable to cast object of type 'System.DirectoryServices.AccountManagement.GroupPrincipal' to type 'System.DirectoryServices.AccountManagement.UserPrincipal'. At line:2 char:1
+ [System.DirectoryServices.AccountManagement.UserPrincipal]::Current
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], InvalidCastException
+ FullyQualifiedErrorId : System.InvalidCastException
This is on a standard Windows 10 20H2 install and doesn't matter if PowerShell is running elevated or not. I've never seen this call return anything other than a UserPrincipal before, so I would be grateful for any advice: is this something I can deal with in code, or is there some underlying issue with the machines that are returning this exception?
I don't know if this is what you're looking for:
$cUser = Get-ADUser $Env:Username -Properties *
This has the most important attributes that you can use for whatever you want later on. It provides as much attribute as the code you posted that didn't work for some of the user.
When I run Connect-PowerBIServiceAccount in Powershell it pops up the Okta window for me to authenticate and that seems to work. But when I run Get-PowerBIWorkspace -All I get this:
Get-PowerBIWorkspace : An error occurred while sending the request.
At line:1 char:1
+ Get-PowerBIWorkspace -All
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (Microsoft.Power...owerBIWorkspace:GetPowerBIWorkspace) [Get-PowerBIWorkspace], HttpRequestException
+ FullyQualifiedErrorId : An error occurred while sending the request.,Microsoft.PowerBI.Commands.Workspaces.GetPowerBIWorkspace
I've done hours of googling and found nothing helpful. I'm using version 1.0.896 of the Powershell modules from MicrosoftPowerBIMgmt. I've tried using Fiddler but that didn't help me. Is there a way to debug? I've tried using "-Debug" and "-Verbose" but neither helped.
UPDATE: The full script I'm trying to use to list out all my workspaces/reports/datasets gets further when executed from the terminal within Visual Studio Code but I don't know why. Eventually it fails too, saying "Operation returned an invalid status code 'TooManyRequests'."
I'm trying to manage some of my Azure Services via Powershell, using http://windowsazurewebsitescheatsheet.info/#powershell as a starting point. I was able to download and import my subscription settings just fine (Import-AzurePublishSettingsFile and Select-AzureSubscription)
After choosing my subscription, I'm attempting to run the Get-AzureWebsite command to view all of my websites, and continue onward from there. When I run that command, however, I get the following:
Import-AzurePublishSettingsFile "C:\AzureCredentials.publishsettings"
Select-AzureSubscription "My Azure Subscription"
Get-AzureWebsite
Get-AzureWebsite : String was not recognized as a valid Boolean.
At line:1 char:1
+ Get-AzureWebsite
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Get-AzureWebsite], FormatException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.Websites.GetAzureWebsiteCommand
Anyone have similar issues? I get this error if I run the command as stated above, or if I specify the name of my website. TIA for any help!
This might be related to a known issue enumerating a sites with SSL bindings
There was new release of Windows Azure Powershell released on 02/12. Please try with the new version.
Please run the command again with -Debug turned on, this will display request and response messages and make it easier to pinpoint the issue.
I am writing a Powershell utility that attempts to enable Offline files, then pin a drive to them. I'm using this documentation for the pin operation: http://msdn.microsoft.com/en-us/library/windows/desktop/bb309186(v=vs.85).aspx
So I have this (simplified to focus on the problem):
$OfflineFilesCache = [wmiclass]"\\localhost\root\cimv2:win32_offlinefilescache"
$OfflineFilesCache.Enable($true)
$DriveArray = , 'W:'
$OfflineFilesCache.Pin($DriveArray, 1, $true)
When I run it, I get the following error:
Exception calling "Pin" : "Provider is not capable of the attempted operation "
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : WMIMethodException
It's not entirely obvious to me what I'm doing that's not correct; I think I am calling it as specified. The enabling the cache part works fine.
I ran it and it worked just fine, might be your drive
I get this message on computers whose offline files cache is disabled. Make sure the cscservice is running.
I am pretty sure that Offline files cache enable/disable requires a system restart.