Update-TFSWorkspace does not work - powershell

Why does
Update-TfsWorkspace [[-Item] <QualifiedItemSpec[]>] [-All] [-Force] [-Overwrite] [-Recurse] [-Version <String>]
not work?
The equivalent tf.exe works just fine in the exact same folder:
tf get itemspec [/version:versionspec] [/all] [/overwrite] [/force] [/preview] [/recursive] [/remap] [/noprompt]
Using Win 8.
Here are the exact commands I'm using:
Update-TfsWorkspace -Item "$/myfilepaht" this does NOT WORK
tf get itemspec "$/myfilepaht" #this WORKS

I had the same problem (probably because I have multiple workspaces)
So I solved it with the following code:
$tfsCredential = Get-Credential;
$tfsServer = Get-TfsServer -Name "https://tfs.tools4ever.com:443/tfs/t4edevnet2010" -Credential $tfsCredential;;
$tfsws = Get-TfsWorkspace -Server $tfsServer -Computer $hostname -Owner $tfsCredential.UserName;
$tfsPath = $tfsws.GetServerItemForLocalItem($filename);
$prop = Get-TfsItemProperty -Item $tfsPath -Server $tfsServer -Workspace $script:tfsws;
$tfsws.Get(#($tfsPath), [Microsoft.TeamFoundation.VersionControl.Client.VersionSpec]::Parse($prop.VersionLatest, $script:tfsws.OwnerName)[0], [Microsoft.TeamFoundation.VersionControl.Client.RecursionType]::Full, [Microsoft.TeamFoundation.VersionControl.Client.GetOptions]::None)

Related

Receive-SFTPFile : A parameter cannot be found that matches parameter name 'RemoteFile'

I am using Transferetto module to download SFTP files, it is able to connect to server and list the server files but throwing error while downloading with below error:-
Receive-SFTPFile : A parameter cannot be found that matches parameter name 'RemoteFile'.
My script is like below:-
Set-ExecutionPolicy RemoteSigned -Scope Process -Force
Import-Module Transferetto
$SftpClient = Connect-SFTP -Server '100.100.00.00' -Username 'FRG_100_22' -Password 'dfggrty'
$List = Get-SFTPList -SftpClient $SftpClient -Path '/FRG'
Get-Childitem -Path "\\data\files" | Remove-Item
$downloadedFiles = #()
# Download multiple files into directory
foreach($originalSFtpFile in $list) {
$downloadedFile = Receive-SFTPFile -SftpClient $SftpClient -RemoteFile $originalSFtpFile -LocalPath "\\data\files" -LocalExists Overwrite -VerifyOptions Retry, None
Write-Host "Downloaded file $($originalSFtpFile.Name) in folder $($downloadedFile.LocalPath)"
$downloadedFiles += ($downloadedFile)
}
Disconnect-SFTP -SftpClient $SftpClient
I used RemotePath instead of RemoteFile and it solved the problem.

Update IIS 6 WebSite Credentials via powershell

I am trying to write a script that will loop through all of my local IIS website and update their physical path credentials whenever I'm forced to update my domain password.
The following works... the first time you run it...
function Set-Site-Credentials(
$SiteElement,
$Credentials
){
$SiteElement.virtualDirectoryDefaults.userName = "$($Credentials.Domain)\$($Credentials.UserName)"
$SiteElement.virtualDirectoryDefaults.password = $Credentials.Password
$SiteElement | Set-Item -Force
}
After running this, I noticed that the following properties also get set
$SiteElement.userName #Same as was set earlier on .virtualDirectoryDefaults
$SiteElement.password #Same as was set earlier on .virtualDirectoryDefaults
Subsequently, anytime I try to update the credentials using the code above, these two properties remain unchanged, and the changes don't take affect in IIS.
So the result is:
$SiteElement.userName #Unchanged
$SiteElement.password #Unchanged
$SiteElement.virtualDirectoryDefaults.userName #New value
$SiteElement.virtualDirectoryDefaults.password #New value
And the IIS site still shows the old username in the UI and the credentials fail.
So naturally I tried setting those extra 2 properties in my update function:
function Set-Site-Credentials(
$SiteElement,
$Credentials
){
$SiteElement.userName = "$($Credentials.Domain)\$($Credentials.UserName)"
$SiteElement.password = $Credentials.Password
$SiteElement.virtualDirectoryDefaults.userName = "$($Credentials.Domain)\$($Credentials.UserName)"
$SiteElement.virtualDirectoryDefaults.password = $Credentials.Password
$SiteElement | Set-Item -Force
}
The code throws no errors or warnings, but the end result is the same, those 2 extra properties remain unchanged.
I am using the following code to get "$SiteElement"
$sites = Get-ChildItem IIS:\Sites
$sites | Foreach-Object { Set-Site-Credentials -SiteElement $_ -Credentials $newCredentials }
Also, at the end of the script I restart IIS using this command:
Restart-Service W3SVC
Ugh, finally found a command that works. All in all I've tried 4 different variation of the same thing from different example around the interwebz, all of which only work the first time. But this command updates properly on subsequent changes:
function Set-Site-Credentials(
$SiteElement,
$Credentials
){
Set-WebConfiguration -Filter "$($SiteElement.ItemXPath)/application[#path='/']/virtualDirectory[#path='/']" -Value #{userName="$($Credentials.Domain)\$($Credentials.UserName)"; password="$($Credentials.Password)"}
}
The full script
param (
[switch]$All,
[switch]$AllPools,
[switch]$AllSites,
[string]$AppPool,
[string]$Site
)
Import-Module WebAdministration
function Set-AppPool-Credentials(
$AppPoolElement,
$Credentials
){
Set-ItemProperty $AppPoolElement.PSPath -name processModel -value #{userName="$($Credentials.Domain)\$($Credentials.UserName)";password="$($Credentials.Password)";identitytype=3}
}
function Set-Site-Credentials(
$SiteElement,
$Credentials
){
Set-WebConfiguration -Filter "$($SiteElement.ItemXPath)/application[#path='/']/virtualDirectory[#path='/']" -Value #{userName="$($Credentials.Domain)\$($Credentials.UserName)"; password="$($Credentials.Password)"}
}
$newCredentials = (Get-Credential).GetNetworkCredential()
$appPools = Get-ChildItem IIS:\AppPools
$sites = Get-ChildItem IIS:\Sites
if($All -or $AllPools){
$appPools | Foreach-Object { Set-AppPool-Credentials -AppPoolElement $_ -Credentials $newCredentials }
}
elseif($AppPool){
$poolElement = ($appPools | Where-Object { $_.name -eq $AppPool })
Set-AppPool-Credentials -AppPoolElement $poolElement -Credentials $newCredentials
}
if($All -or $AllSites){
$sites | Foreach-Object { Set-Site-Credentials -SiteElement $_ -Credentials $newCredentials }
}
elseif($Site){
$siteElement = ($sites | Where-Object { $_.name -eq $Site })
Set-Site-Credentials -SiteElement $siteElement -Credentials $newCredentials
}
Restart-Service W3SVC

Powershell SCCM 2012 Moving Driver Package

so i have this lovely script that will make folders and driver packs in SCCM 2012, it created the folder and driver packages, but i can't work out how to put them in the correct folders. I thought that PkgFlags would do it but that seems to do nothing and i can't find a function to move the package.
i have worked on this for several days and have gotten nowhere
please help
$SCCMSiteCode = Read-Host "SCCM Site Code"
$PackageNamePath = Read-Host "Driver Package Original Path"
$PackageSourcePath = Read-Host "Driver Package Source Path"
$FolderArray1 = Get-ChildItem -Path "$PackageNamePath"
foreach ($FolderList1 in $FolderArray1)
{
if (($FolderList1.name -Like "Server*") -or ($FolderList1.name -Like "Windows*"))
{
$Argument1 = #{Name = "$FolderList1"; ObjectType = 23; ParentContainerNodeId = 0}
Set-WmiInstance -Namespace "root\sms\site_$SCCMSiteCode" -Class "SMS_ObjectContainerNode" -Arguments $Argument1
$GetID1 = Get-wmiObject -Namespace root\SMS\site_$SCCMSiteCode -Query "Select name,containernodeid from SMS_ObjectContainerNode" | select name,ContainerNodeID | Where-Object {$_.Name -eq $FolderList1}
$FolderArray2 = Get-ChildItem -Path "$PackageNamePath\$FolderList1"
foreach ($FolderList2 in $FolderArray2)
{
if (($FolderList2.name -NotLike "Server*") -or ($FolderList2.name -NotLike "Windows*"))
{
$DateTime = get-date -Format yyyy.MM.dd-hh.mm.ss
$Milliseconds = (get-date).millisecond
$FullDateTime = "$DateTime.$Milliseconds"
New-Item -ItemType Directory -Path "$PackageSourcePath\$FullDateTime"
$PackageName = "$FolderList2 - $FolderList1"
$Argument2 = #{Name = "$PackageName"; PkgSourcePath = "$PackageSourcePath\$FullDateTime"; PkgSourceFlag = 2; PkgFlags = $GetID1.ContainerNodeID}
Set-WmiInstance -Namespace "root\sms\site_$SCCMSiteCode" -Class "SMS_DriverPackage" -Arguments $Argument2
}
}
}
}
If you are talking about folder in SCCM itself, there is another wmi class you need called SMS_ObjectContainerItem. It basically tells the driver which folder to go in.
I haven't actually scripted it in 2012, but in a script I wrote that creates advertisements, I had code that looked like this:
#This gets the folder from wmi. $advContName is the name of the folder I want the ADV to end up in
$advContainer = gwmi -name root\sms\site_ia1 -computer itsnt353 -query "Select * from SMS_ObjectContainerNode WHERE Name='$advContName' AND ObjectType='3'"
$moveADV = ([WMIClass]\\itsnt353\root\sms\site_ia1:SMS_ObjectContainerItem").CreateInstance()
$moveADV.InstanceKey = $advID
$moveADV.ObjectType = 2;
$moveADV.ContainerNodeID = $advContainer.ContainerNodeID
$moveADV.Put()
I hope this helps.

rdesktop shell escaping issue

I'm trying to send this:
Get-WmiObject Win32_PNPEntity |Where{$_.DeviceID.StartsWith("PCI\VEN_10DE") -or $_.DeviceID.StartsWith("PCI\VEN_1002")}
over rdesktop like:
rdesktop -a8 209.** -u ** -p ** -s "cmd.exe /K powershell.exe Get-WmiObject Win32_PNPEntity |Where{\$_.DeviceID.StartsWith("PCI\VEN_10DE") -or $_.DeviceID.StartsWith("PCI\VEN_1002")}"
But windows' shell says:
'Where{$_.DeviceID.StartsWith' is not recognized as an internal or externa....
What am I doing wrong?
why not using powershell wmi remoting?
$cred = get-credential
Get-WmiObject Win32_PNPEntity -computerName MyRemoteComputerName - credential $cred |Where{$_.DeviceID.StartsWith("PCI\VEN_10DE") -or $_.DeviceID.StartsWith("PCI\VEN_1002")}
-credential are only needed if the actual user running powershell isn't administrator of remote machine.
Hi I needed to do some thing like this once so i wrote some code that can send any ps code to a remote computes and display the results in the ps window on your pc.
Just remember to enable powershell remoting on both pc's.
function remote-pscode ($ServerName,$UserName,$password,$PSCode)
{
$global:RemoteCode = $args[0]
Write-Host $RemoteCode
$conprops = (Get-Host).UI.RawUI
$buffsize = $conprops.BufferSize
$buffsize.Height = 800
$conprops.BufferSize= $buffsize
# Set the user name you would like to use for the connection
$global:RemoteUserName = $UserName
$global:RemoteServerName = $ServerName
# Set the password you would like to use for the connection
# Check to see if you have a file on you drive c:\cred.txt with a password to use in it,if you don't it will create one
# for you and ask you for the password you would like to use
$global:RemotePassword = convertto-securestring $password -AsPlainText -Force
$global:credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist $RemoteUserName,$RemotePassword
#Create a connection to the remote computer , put a list of IPAddresses or Computer Names.
$global:session = new-PSSession -ComputerName $RemoteServerName -Credential $credentials
$ScriptBlock = $executioncontext.invokecommand.NewScriptBlock($RemoteCode)
invoke-command -Session $session -ScriptBlock $ScriptBlock
#Close the sessions that where created
$global:closesession = Get-PSSession
Remove-PSSession -Session $closesession
}
remote-pscode -ServerName "NameOfRemotePC" -UserName "UserName" -password "password" -PSCode "any powershell code you want to send to the remote pc"
Several things here: put your PS commands in a script block (or a script). Also, why don't you simply use wmic.exe ?

Booting from an ISO image using PowerCLI scripts

How do I make the following script work? Currently I am able to create a new virtual machine in my server. I wish to also load the Windows ISO image and do an unattended installation in the virtual machine. How shall I edit the script to make this work?
# Virtual Center Details
$server_address = "xxxxx"
$username = "xxxxx"
$password = "xxxxx"
$iso = "WINXP_X86_SP3_CD.ISO"
Get-VIServer -Server $server_address -Protocol https -User $username -Password $password
foreach ($vmm in $array)
{
$vmm = "VirtualMachine"
New-VM -name $vmm -DiskMB 20000 -memoryMB 2000
Get-VM $vmm | Get-CDDrive | Set-CDDrive -IsoPath $iso -StartConnected $true -Confirm:$false
$value = "5000"
$vm = Get-VM $vmname | Get-View
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.BootOptions = New-Object VMware.Vim.VirtualMachineBootOptions
$vmConfigSpec.BootOptions.BootDelay = $value
$vm.ReconfigVM_Task($vmConfigSpec)
Start-vm -vm $vmname
}
my issue is with the ISO PATH image. I am getting the error "Invalid datastore format"
You are specifying isopath using IsoPath parameter, which is the datastore path to the ISO, not simply the ISO name. From your code you are not indicating any datastore.
The syntax for a datastore path is:
"[yourdatastore] IsoFolder\$iso"
Example got from PowerCLI reference online:
$cd = New-CDDrive -VM $vm -ISOPath "[sof-20666-esx:storage1] ISO\testISO.iso"
Set-CDDrive -CD $cd -StartConnected -Connected