I created a powershell (DBOff.ps1) script that shuts down my server database before it shutdowns my server (Windows 2008 R2). This script is held locally on the server itself and is fully functional. The problem is I need to create a batch file and a second Powershell script to run said original script using another computer. These two scripts will be called from the office Windows 7 machine in case of a power failure. All remoting configurations have been made and If I manually enter the commands in the PowerShell console they work just fine.
Here is the Batch File:
powershell.exe -file C:\Users\baftp\Documents\APCPowershellWork\InvokePowershell.ps1
pause
________________
Here is my Local Windows 7 InvokePowershell.ps1 script
$CN='192.168.48.134'
$USRNM='user'
# *****************************************************
# Create New Remote Session
# *****************************************************
#$MicrosLab= Enter-pssession -computername 192.168.47.134 -credential baftp
start-sleep -s 3
# *****************************************************
# Find and Run the Powershell Script on remote PC
# ****************************************************
Invoke-Command -computername $CN -credential $USRNM {Set-Location
C:\Users\baftp\Documents\PSScripts\microsoff.ps1}
Even though I have successfully connected to the remote PC this is the error i get
Cannot find path 'C:\Users\baftp\Documents\PSScripts\microsoff.ps1' because it
does not exist.
+ CategoryInfo : ObjectNotFound: (C:\Users\baftp\...s\microsoff.p
s1:String) [Set-Location], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLo
cationCommand
I used the invoke- command thinking this would help the problem since Enter-PSSession wasnt working. What am I doing wrong?
Also is there a way to save username and password in the -credential cmdlet. Im creating this batch file for a user that will not know the password.
I am Using Powershell 2.0 on both machines<o:p></o:p>
Thanks in advance