I’ve created a script that configures our servers based on passed parameters, and it runs locally without issue. When I try to perform an Invoke-Command, it fails completely. There are no double-hop scenarios here, to be clear. Below is a snippet of code, some of the arguments have been redacted as has the argument list, but the issue is not with those.
If you look you can see that I’m creating a session, and then doing an invoke-command with that session where I kick off my script and pass in the parameters. However the script fails time and again. Here is what fails:
$NetAdapter = Get-NetIPConfiguration $ips = Get-NetIPAddress -AddressFamily IPv4 -InterfaceIndex $NetAdapter.InterfaceIndex Install-PackageProvider -Name NuGet Import-Module SqlPs
Why are these failing? I want a script that I can run locally and it works, which I’ve created and it works great, and I want to be able to remotely invoke it…these don’t seem like they should be things that don’t work within a session yet they are.
$PSSession = New-PSSession -ComputerName $($Server.ServerName) -EnableNetworkAccess -Credential $DomainCredentials And yes, C:\Install-SingleInstance.ps1 does exist on the box at C:\. Invoke-Command -Session $PSSession -ScriptBlock { cd C:\; .\Install-SingleInstance.ps1 }