gwmi win32_service -ComputerName IP –credential userName returns Access denied but Enter-PSSession -ComputerName IP -Credential Personal works - powershell-5.0

Running this powershell command
Enter-PSSession -ComputerName 192.168.1.184 -Credential Personal
command works fine. The username and password is accepted.
Again, running this command:
Invoke-Command -ComputerName 192.168.1.184 -ScriptBlock { Get-ChildItem C:\ } -credential Personal
Also works fine and it displays the folders in drive C. It also implies that i can login. When i run this command:
gwmi win32_service –credential Personal –computer 192.168.1.184
I get "gwmi : Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"
So does this:
Copy-Item -Path c:\d\test.txt -Destination \\192.168.1.184\c$\dep\test.txt
I've tried everything i could think of and i still fail. My goal is to copy files to target computers and execute these files. I have about 52 machines and i need to be able to install these programs.
Anyone knows why this isn't working?

Related

Powershell Won't Exit After Running Cmd.exe

I'm using powershell to
Close Access Database,
Download updated Access front end to local machines,
Update (overwrite) local documents, and
Launch the Access database with parameters using cmd.exe.
Everything works fine, but the Exit command doesn't work after using cmd.exe command to launch the database.
If I comment out the cmd.exe command, then the Exit command works just fine. But if I use the Exit command, the script stops there and the Exit command does not work. Below is the entire code that I'm talking about.
## Close Microsoft Access
Stop-process -name MSACCESS -Force
## Download updated Access database to local machine
Copy-Item "F:\New_DB\Win7DBDocs\WC_Sys.mdb" -Destination "C:\DB_Docs" -Recurse -Force
## Copy Documents and Spreadsheets to local machine
echo "Overwriting files C:\DB_WPDocs"
Copy-Item -Path "F:\New_DB\DB_WPDocs\*" -Destination "C:\DB_WPDocs" -Recurse -Force
## Launch Microsoft Access with Parameters
cmd.exe /c "C:\Program Files (x86)\Microsoft Office\root\Office16\MSACCESS.EXE" "C:\DB_Docs\WC_Sys.mdb" /WRKGRP "F:\DB_Docs\Secured.mdw"
Exit
cmd.exe will block until MSACCESS.EXE exits.
To make cmd.exe launch the program and return immediately, use the start command:
cmd.exe /c start "C:\Program Files (x86)\Microsoft Office\root\Office16\MSACCESS.EXE" "C:\DB_Docs\WC_Sys.mdb" /WRKGRP "F:\DB_Docs\Secured.mdw"
... or drop cmd.exe completely and use the Start-Process cmdlet instead:
Start-Process "C:\Program Files (x86)\Microsoft Office\root\Office16\MSACCESS.EXE" -ArgumentList "C:\DB_Docs\WC_Sys.mdb", /WRKGRP, "F:\DB_Docs\Secured.mdw"

SSH Permission Denied WindowsPowerShell

I'm trying to connect to my Jetsonnano from Windows 10 via ssh. If i use my Ubuntu Pc everything works fine, but if i use my Windows 10 Laptop I see this Error:
Permission denied, please try again.
After I type in the correct Password.
Thank you all for your Time and Help
Check for the pwsh executable path first:
Get-Command pwsh | select Source
this will give you the path of powershell core path
Get-Command powershell | select Source
this command on the other hand will return the path of earlier version of powershell
i.e. powershell version 5 etc.
I was also having the same issue. After I blindly copied a command from a blog post and executed it:
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell
-Value "C:\Program Files\PowerShell\7\pwsh.exe" -PropertyType String -Force
I scratched my head for more than 10 hours.
then I did debug run of sshd with this command on Windows 10 host:
sshd -d
and tried to connect from my Linux machine as usual:
ssh james#192.168.1.123
I saw this line in my Windows debug prompt:
User james not allowed because shell c:\\program files\\powershell\\7\\pwsh.exe does not exist
so I executed this command again with modified path to Powershell 7 executable:
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell
-Value "C:\Program Files\WindowsApps\Microsoft.PowerShell_7.2.1.0_x64__8wekyb3d8bbwe\pwsh.exe"
-PropertyType String -Force
and it fixed my problem.
Open the terminal
start ssh-agent eval$(ssh-agent -s)
add a key to the ssh-agent (if prompted, enter the password)
ssh-add ~/.ssh/id_rsa
test connection ssh -T git#github.com
Clone the repo git clone git#github.com:antonykidis/Setup-ssh-for-github.git
Enjoy
Important:
Every time you start a new Terminal instance:
You will have to call ssh-agent.
Add RSA key to the ssh-agent.
Loop through these steps every time you close/open the terminal.
Because the terminal “loses” ssh-agent with its keys on every session.
Check this information:
Open C:\Program Files\Git\etc\ssh\ssh_config (if that’s where you installed Git)
Add lines
Host github.com or ubuntu host machine
IdentityFile ~/.ssh/

Add-AzTableRow command is not available in Azure Cloud Shell

I'm trying to insert new row in my table storage by using Azure Cloud Shell but I'm facing below exception. So let me know any other command that we need to use to insert.
Blockquote
Add-AzTableRow: The term 'Add-AzTableRow' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Blockquote
Below are the command:
$partitionKey1 = "partition1"
$partitionKey2 = "partition2"
Add-AzTableRow `
-table $cloudTable `
-partitionKey $partitionKey1 `
-rowKey ("CA") -property #{"username"="Chris";"userid"=1}
According to the error, it seems that you do not install the module AzTable. Please run the command Get-InstalledModule to check if you have installed the module.
If you have not installed the module, please run the command Install-Module -Name AzTable -Force to install it.
For example
Install-Module -Name AzTable -Force
Import-Module AzTable
$resourceGroup = "<your group name>"
$storageAccountName ="<your account name>"
$storageAccount=Get-AzStorageAccount -ResourceGroupName $resourceGroup -Name $storageAccountName
$ctx = $storageAccount.Context
$tableName = "<table name>"
$cloudTable = (Get-AzStorageTable –Name $tableName –Context $ctx).CloudTable
$partitionKey1 = "partition1"
Add-AzTableRow -table $cloudTable -partitionKey $partitionKey1 -rowKey ("CA") -property #{"username"="Chris";"userid"=1}

How to enable Bitlocker for C drive or any drive?

I am using following PowerShell script to enable BitLocker on C drive,
$SecureString = ConvertTo-SecureString "ABC123" -AsPlainText -Force
Enable-BitLocker -MountPoint "C:" -EncryptionMethod Aes256 -Password $SecureString
And getting the output,
cmdlet Enable-BitLocker at command pipeline position 1
Supply values for the following parameters:
PasswordProtector:
I tried to pass parameters
Enable-BitLocker -MountPoint "C:" -EncryptionMethod Aes256 Add-BitLockerKeyProtector -Password $SecureString -RecoveryKeyPath "\fileserver\keys" -RecoveryKeyProtector
but still, it's showing errors.
Can anyone have a running script to enable BitLocker?
Find the solution for my question, script to configure BitLocker with password,
$SecureString = ConvertTo-SecureString "123456789" -AsPlainText -Force
Enable-BitLocker -MountPoint "D:" -EncryptionMethod Aes256 -PasswordProtector -Password $SecureString

Execute remote powershell script from local system

I am new to this powershell..Execuse me if anything wrong here.
Now coming straight to the question I have a powershell script stored in one of the drive say "D:\myfile.ps1" which is in remote system.
Now I need to execute this script from my local system and this is the way I have done
ExecuteCommand(Directory.GetCurrentDirectory & "\Psexec \\myservername -i -u username -p password powershell.exe Invoke-Command -ComputerName \\myservername -FilePath D:\myscript.ps1")
The result is showing me this way without any output giving me an error
"powershell exited on myservername with error code 1'
And If run this script to run .exe on the same server it's working fine
ExecuteCommand(Directory.GetCurrentDirectory & "\psexec \\myservername -u username -p password D:\myfile.exe")
So what's the correct way to execute my script to run on remote desktop ?
Update after suggestions:
Can you just try :
ExecuteCommand(Directory.GetCurrentDirectory & "\Psexec \\myservername -i -u username -p password powershell.exe -command "&{Invoke-Command -ComputerName \\myservername -FilePath D:\myscript.ps1}"