How to get output from invoke-command
hi,
here how use command: works correctly , job need info in log file.
so in script file write write-output nothing appear in log file
$filemigr = "$scriptpath\migrateuser.ps1" $sess = new-pssession $servername -authentication credssp -credential $cred $log = invoke-command -filepath $filemigr -session $sess -outvariable log | out-file $pathfile -append
here ps1 file
'add-pssnapin microsoft.sharepoint.powershell [microsoft.sharepoint.spsecurity]::runwithelevatedprivileges({ write-output "testtttttttttt" $accountfrom = "dom\xxxx" $accountto = "dom\yyyy" $webapps = get-spwebapplication $usertoreplace = "" $userreplaced = "" foreach($webapp in $webapps){ $cptsc = 1 foreach($sc in $webapp.sites){ $siteurl = $sc.url $spsite = new-object microsoft.sharepoint.spsite($siteurl) $servicecontext = get-spservicecontext($spsite) $profilemanager = new-object microsoft.office.server.userprofiles.userprofilemanager($servicecontext) $web = $spsite.openweb() $siteusers = $web.siteusers if($usertoreplace -eq $null){ foreach($user in $siteusers){ if($user.loginname -eq $accountfrom){ $usertoreplace = $user $userreplaced = "i:0#.w|$accountto" } } } } } write-output "has user profile from:$accountfrom $profilemanager.userexists($accountfrom)" write-output "has user profile to:$accountto $profilemanager.userexists($accountto)" if($userreplaced -ne "" -and $profilemanager.userexists($accountto) -and $profilemanager.userexists($accountfrom)){ move-spuser -identity $usertoreplace -newalias $userreplaced -ignoresid }}); i found a lot of post nothing worked.
thanks help
to many things:
$filemigr = "$scriptpath\migrateuser.ps1" $sess = new-pssession $servername -authentication credssp -credential $cred invoke-command -filepath $filemigr -session $sess | out-file $pathfile -append
\_(ツ)_/
Windows Server > Windows PowerShell
Comments
Post a Comment