576 questions
2
votes
1
answer
89
views
Invoke-Command remote script behaviour on Server 2016 vs 2025
I have an existing script which has worked for some time running on a Windows Server 2016 server, but which gives me an error when run on its relacement 2025 server. What is strange is the error doesn'...
1
vote
1
answer
109
views
In PowerShell, I cannot transfer System.Data.DataTable using the invoke-command to the remote host
Here is a script in which I am trying to pass a variable of type System.Data.DataTable via invoke-command to the remote host:
function Test1 {
param (
[System.Data.DataTable]
$...
1
vote
2
answers
99
views
Invoke-Command and/or Start-Process fail if no user session is active on the remote system
tl;dr
If I locally start Invoke-Command to start an EXE file remotely, it fails, if there is no active user session on the remote system.
I am facing the challenge of installing an application with ...
1
vote
2
answers
112
views
Powershell Invoke-command works but returning an exception
My script opens a WebDAV session to my server, but on some occasions the command is stuck, without any exception.
The command is $Session.Open($SessionOptions).
To monitor the command with a timeout, ...
1
vote
1
answer
128
views
PowerShell: executing C# Class (FindFiles) as an Add-Type definition on a remote system using Invoke-Command is extremely slow
I want to find all Package.json files on a remote system using PowerShell. In order to optimize this, I found a C# class on the internet adjusted it and now would like to use it.
This code runs really ...
0
votes
3
answers
177
views
Issue "Invoke-Command & Get-Content with large files"
this is my first post because i can't find a solution and i don't understand whats wrong...
I have a simple script which should read a large logfile on a client with get-content in an invoke-command.
$...
0
votes
1
answer
112
views
Powershell invoke-command: why isn't this engaging the foreach loop? [duplicate]
OK, I'm piggybacking off my previous question Powershell script to get IIS app pool recycling time from servers and wondering what I'm doing wrong
I have a list of IIS app pools (apppools.txt) and a ...
0
votes
1
answer
195
views
Use Invoke-Command create new user with secure password on remote client
I am struggling to resolve what should be a simple thing.
I am looping through a list of computers $bcs for each $bc in $bcs.
I run the command below to remotely create the user account with the ...
1
vote
0
answers
32
views
Error using Powershell's Invoke-Command with Filepath [duplicate]
I have a Powershell script 'hello-world.ps1', which is overly simple, it takes no arguments and simply writes some text to the console:
Write-Host "Hello world"
With the command prompt, ...
2
votes
2
answers
81
views
Why do I get access denied using Invoke-Command on localhost?
I have valid credentials of a Windows service account stored in $creds and want to use them to access the C:\temp\ directory on another server called remotehost. I use Invoke-Command to execute the ...
1
vote
0
answers
1k
views
Executing sfc.exe /scannow on Remote Computer Using PowerShell Doesn't Show Process
I'm attempting to run sfc.exe /scannow on a remote computer using PowerShell's Start-Process, but I'm unable to confirm whether the process starts on the remote machine. When I check for any sfc ...
-1
votes
1
answer
259
views
Understanding PowerShell SessionOption OperationTimeout Behavior with Invoke-Command
I've set the OperationTimeout to 10 seconds, but when I run a command that sleeps for 20 seconds inside an Invoke-Command block on a remote computer, I don't get an error. Here's the code:
$...
0
votes
1
answer
353
views
Efficiently Retrieving Microsoft Edge Versions from Multiple Remote Machines Using PowerShell Jobs
$command = {
try {
$package = Get-Package -Name "*Microsoft Edge*"
return [PSCustomObject]@{Version = $package.Version}
} catch {
return &...
0
votes
2
answers
367
views
How to get return value of Invoke-Expression in Powershell
So this is my code
$result = Invoke-Command -Session $session -FilePath $ps1
How do I get the result given by $ps1?
The code of that function is supposed to give a true false result like in the ...
1
vote
1
answer
2k
views
When using invoke-command with credentials, credential parameter not properly initialized
So I tried calling the following code with and without credentials.
$username = "user"
$password = "password"
$cred = new-object -argumentlist $username, $password
#Invoke-Command ...
0
votes
1
answer
358
views
Powershell Add-DhcpServerInDC Access Denied When Using it with Invoke-Command
I'm trying to automate the process of setting up a multi-network DHCP. 172.16.0.13 is the network the Adatum domain is on. 172.16.18.21 is the network the relay agent is on. Both of these have the ...
0
votes
1
answer
143
views
In Azure Runbook - map a drive to remote server
I have a working PS Script to run in an Azure Runbook to map a drive to a remote server to then copy very specific files to Azure blob storage.
NOTE: The entire script works 100% in VSCode > ...
2
votes
0
answers
88
views
Invoke-Command is failing in combination with PackageProvider commands
I am trying to install nuget package provider by using:
Find-PackageProvider -Name NuGet -ForceBootsrap -IncludeDependencies in combination with Invoke-command -session $mysession
But when running it ...
1
vote
0
answers
166
views
Invoke-command works only when any user is logged (msi install)
I've got a problem with running Invoke-Command on remote Computer with WinRM up and running. I've configured and run WinRM, but Invoke-Command with task of Silent Install is not successfully run until ...
-1
votes
1
answer
76
views
Pass local variable to invoke-command [duplicate]
I am executing the below Powershell script from a remote server. However it is failing as follows:
PS C:\\Windows\\system32\> Invoke-Command -Session $evServerSession -scriptblock {
\\>\> $...
-1
votes
1
answer
452
views
Start-Process is not working in Invoke-Command
$upgradeInvoke = Invoke-Command -Session $session -ScriptBlock {
try {
Shutdown.exe /r /f /t 1200 /d p:4:2 /c "Triggerd Reboot Timer for 20 minitus"
$...
0
votes
1
answer
291
views
Invoke-command unable to copy a shared network folder?
I have been working on a script that can remove an old version of zabbix from our servers, and install the latest version.
I am having a problem copying a file from a shared folder when I am using ...
0
votes
0
answers
602
views
get-acl access property is just System.Security.AccessControl.FileSystemAccessRule when run inside invoke-command
I'm tying to get the permissions of all the folders in a path on a remote server as efficiently as I can so I want to make as few calls as I can (avoiding looping through all folders and running a get-...
0
votes
1
answer
493
views
Add-DnsServerResourceRecordCName throws CimException when run through Invoke-Command
This code:
$zonename = "mydomain.ca"
$username = 'mydomain\svc_dns'
$dnsserver = 'dns.mydomain.ca'
$password = 'password'
$securePassword = ConvertTo-SecureString $password -AsPlainText -...
1
vote
1
answer
2k
views
Execute Start-Process Powershell Script on a Remote Computer
I open PowerShell as admin and use the following line of code to run an offline file for windows updates. It works fine
Start-Process 'wusa.exe' -ArgumentList 'C:\Temp\windows10.0-kb5032189-...
0
votes
1
answer
402
views
Unable to create Registry value through Powershell
I have multiple machines that need certificate padding enabled. My script looks like this:
$ComputerName = Read-Host "Please Enter Computer Name"
Invoke-Command -ComputerName $ComputerName -...
2
votes
1
answer
398
views
How to error handle Invoke-Command over SSH
I'm currently working with a script that utilizes the Invoke-Command over SSH as shown below. While it works well, I'm looking to implement exception handling, specifically for scenarios where the ...
2
votes
1
answer
832
views
Get-Service fails but Invoke-Command {Get-Service} succeeds
I'm trying to run a series of PowerSHell commands on my desktop computer that connect to one of the corporate servers and checks on the status of the services there. I'm doing a Run As on the ...
0
votes
0
answers
83
views
I'm having issues trying to remotely install certificates on a list of servers using PowerShell
I've been tasked with updating some certificates on some remote servers. We have a TON of servers and not all of them have these certs installed.
To make a short story long....
There are 2 different ...
1
vote
1
answer
233
views
Unable to Launch or Execute New Window or Applications on Remote System Using Windows PowerShell "Invoke-Command"
In Windows Powershell (admin):
Connect to Remote Windows
$session = New-PSSession -ComputerName "xx.xx.xx.xx"
Attempting Remote Execution
Invoke-Command -Session $session -ScriptBlock {
...
0
votes
1
answer
364
views
How can I call a Function, inside of a Function, inside of Invoke-Command ScriptBlock?
I have been racking my brain over this and scouring the internet for an answer, but I can't seem to find anything for my specific situation. I have created a set of Functions that help me add/remove ...
1
vote
2
answers
206
views
Different results with invoke-command vs local command
Executing practically the same command but remotely delivers no results in Powershell.
This delivers empty lines:
$certificates = Invoke-Command -ComputerName $computername -ScriptBlock {
Get-...
0
votes
1
answer
851
views
Using global Variable in Invoke-Command
I am trying to figure out a way to use a global variable in a Invoke-Command without success.
There are some posts which I tried but they do not work in this use-case.
So what I have is a script like ...
1
vote
4
answers
859
views
Powershell: Scripted Remote Installation using Start-Process of Notepad++ hangs indefinitely
I have written a script, that takes a csv file with vulnerable Servers and should replace the installed version of Notepad++.
I uninstall the currently installed version from the machine, push a ...
0
votes
1
answer
428
views
run .exe as administrator on a vm with Invoke-VMScript Powershell 7
I need to be able to launch command by shell console or powershell having the administrator window in powershell 7.
I have launched several commands with Start-Process but none of them returned the ...
1
vote
1
answer
523
views
Using variable in Select-Object in Powershell
I have a table which is created using Time as the Column names. However if the first row does not have data in certain Hours(column) then the column does not show the column for the rest of the table....
0
votes
1
answer
76
views
Throwing null error when trying to rename directory via Invoke-Command in Powershell [duplicate]
I'm basically writing a program that takes an input of a current folder path from a user and a new folder path that they want to rename it as. Then the program remotes into a file server that the ...
0
votes
1
answer
116
views
How to get local variable value from Invoke-command -Asjob?
I want to run [System.Net.Dns]::GetHostAddresses("mail") on remote computers and write it.
Foreach($PCName in $PCNameArray) {
$arrayJobs += Invoke-Command -Credential $cred -scriptblock {...
0
votes
1
answer
148
views
Powershell invoke-command returns one object property only
I try to get Windows audit policies on several Windows servers with an Invoke-Command cmdlet. It works fine for all servers, except one where I get only the first object property (the added ...
1
vote
1
answer
1k
views
Powershell - Invoke-Command : Parameter set cannot be resolved using the specified named parameters [duplicate]
[Could not find any relevant nor working answer, I checked the parameters, they are legit]
I try to run an executable with its respective parameters, but with powershell
here is the line:
Invoke-...
0
votes
1
answer
62
views
How to save a table to a log file without replacing the information
I am trying to get a shadow storage information from remote computers.
I could get the information and store in a variable as table.
But every time the log file is being overwrite by the new ...
0
votes
0
answers
306
views
Get-Service shows different results when run directly on server and when run remotely via Invoke-Command
when I execute:
$serviceName = "Tanium Client"
Get-Service $serviceName
Directly On Server
it gives:
Status Name DisplayName
Running Tanium Client Tanium Client
but ...
3
votes
1
answer
233
views
Powershell Invoke Command Export to Excel
Having a few issues with this PowerShell code:
$vmslist = Import-Csv -Path .\vmsList.csv -Delimiter ',' | ForEach-Object {
$_.Servers
$vms = [string]$env:COMPUTERNAME
$currentVms = $_....
0
votes
1
answer
1k
views
Get-AzConsumptionUsageDetail returns 'BadRequest'
I had a 'Bad Request' error while trying to use Get-AzConsumptionUsageDetail on my Powershell script to get consumption reports of multiple Azure subscriptions, I looked on the internet and it seems ...
0
votes
1
answer
297
views
Running a bat script with invoke-command works on vm:s but not on physical machines
I try to run an oracle bat script (opatch.bat) remotely to gather info on patchlevels on oracle agent installations.
The command to run is
invoke-command -ComputerName <remote_computer> -...
0
votes
1
answer
818
views
Powershell - invoke-command - if reg exists
I have wrote that script but the result is the same for all the computer.To be more precise if my device has the registry Name then all have it which does not reflect the reality.Same if my device ...
0
votes
2
answers
636
views
Invite Users to Azure DevOps Project via REST API (PowerShell)
The goal of the script is to invite a user to a specific project in Azure DevOps via REST. Invoke Request was used to add a user with the appropriate permissions.
I'm able to successfully retrieve the ...
0
votes
0
answers
547
views
Powershell Onedrive uninstall script, file not found
I'm trying to make a powershell script to uninstall Onedrive from users computers by running Invoke-Command -computername computer1 -filepath script.ps1
but i keep getting issues with the last step.
...
1
vote
1
answer
5k
views
Run Powershell Script as Administrator remotely
Script_A.ps1 on Server A:
Invoke-Command -ComputerName Server B -ScriptBlock{
Set-Location "C:\Path"
.\Script_B.ps1
}
The Script "Script_B.ps1":
Set-Location "C:\...
0
votes
0
answers
58
views
py command breaks in ps1 but not in PowerShell terminal
The py -3 -m venv venv command works when typed manually into a Powershell terminal, but breaks when called from a ps1 script.
What specifically must be changed in the code below in order for the ...