At TechEd North America, we announced Azure Traffic Manager support for endpoints external to Azure. We are happy to announce a further enhancement, adding support for weights when using round-robin load-balancing. Together, these features enable a range of new scenarios, including distributing traffic in hybrid scenarios between on-premises and the cloud.
Azure Traffic Manager External Endpoints and Weighted Round Robin via PowerShell
Create Single Text File with Variables from CSV File
I am needing to create a single text file that has 1251 occurrences of the following:
DECLARE @return_value int
EXEC
@returnvalue = [dbo].[sproc_x_y_z]
@providerassetid = N'$asset',
@providerid = N'xyz',
@serviceCollectionId = NULL
SELECT 'Return Value' = @return_value
The $asset is a unique value contained in a separate CSV file that has 1251 different values. I am very new to powershell and am not sure how to create a file that outputs the above text and then insert the variable from the CSV file.
XML - how to get attributes of a property and not just the property text.
I am sure this is simple, but I am struggling to get the attributes of an XML property to be displayed. I can get the property text, but I would like the also get the name or display-name attribute values as well.
The simple Powershell I am using to get the text is this:
[code]
[xml]$xmlFile1= Get-Content "C:\show__controller_statistics.xml"
$test = $xmlFile1.RESPONSE.OBJECT[0].PROPERTY[0]."#text"
$test1 = $test.ToString()
Write-Host "<value>$test1</value>"
[/code]
The above gets me a response of <value>controller_A</value> but I would also like to the the display-name (in this case "Durable ID") saved as another variable?
The XML file is
[code]
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<RESPONSE VERSION="L100">
<COMP G="0" P="1"/> <OBJECT basetype="controller-statistics" name="controller-statistics" oid="1" format="rows">
<PROPERTY name="durable-id" type="string" size="14" draw="true" sort="string" display-name="Durable ID">controller_A</PROPERTY>
<PROPERTY name="cpu-load" type="uint32" size="10" draw="true" sort="string" display-name="CPU Load">5</PROPERTY>
<PROPERTY name="power-on-time" type="uint32" size="22" draw="true" sort="string" display-name="Power On Time (Secs)">6376142</PROPERTY>
<PROPERTY name="write-cache-used" type="uint32" size="18" draw="false" sort="string" display-name="Write Cache Used">21</PROPERTY>
<PROPERTY name="bytes-per-second" units="KB" type="string" size="18" draw="true" sort="string" display-name="Bytes per second">5154.8KB</PROPERTY>
<PROPERTY name="bytes-per-second-numeric" type="uint32" size="18" draw="true" sort="string" display-name="Bytes per second">5154816</PROPERTY>
<PROPERTY name="iops" type="uint32" size="16" draw="true" sort="string" display-name="IOPS">94</PROPERTY>
<PROPERTY name="number-of-reads" type="uint64" size="16" draw="true" sort="string" display-name="Number of Reads">5779685975</PROPERTY>
<PROPERTY name="read-cache-hits" type="uint64" size="16" draw="false" sort="string" display-name="Read Cache Hits">1708899169</PROPERTY>
<PROPERTY name="read-cache-misses" type="uint64" size="16" draw="false" sort="string" display-name="Read Cache Misses">567658866</PROPERTY>
<PROPERTY name="number-of-writes" type="uint64" size="16" draw="true" sort="string" display-name="Number of Writes">824134848</PROPERTY>
<PROPERTY name="write-cache-hits" type="uint64" size="16" draw="false" sort="string" display-name="Write Cache Hits">624783731</PROPERTY>
<PROPERTY name="write-cache-misses" type="uint64" size="16" draw="false" sort="string" display-name="Write Cache Misses">642082336</PROPERTY>
<PROPERTY name="data-read" units="TB" type="string" size="16" draw="true" sort="string" display-name="Data Read">65.3TB</PROPERTY>
<PROPERTY name="data-read-numeric" type="uint32" size="16" draw="true" sort="string" display-name="Data Read">65370081142784</PROPERTY>
<PROPERTY name="data-written" units="TB" type="string" size="16" draw="true" sort="string" display-name="Data Written">16.7TB</PROPERTY>
<PROPERTY name="data-written-numeric" type="uint32" size="16" draw="true" sort="string" display-name="Data Written">16752711755264</PROPERTY>
<PROPERTY name="reset-time" type="string" size="25" draw="true" sort="datetime" display-name="Reset Time">2013-04-30 16:25:54</PROPERTY>
<PROPERTY name="reset-time-numeric" type="uint32" size="25" draw="true" sort="datetime" display-name="Reset Time">1367339154</PROPERTY>
<PROPERTY name="start-sample-time" type="string" size="25" draw="false" sort="datetime" display-name="Start Sample Time">2013-07-13 11:30:02</PROPERTY>
<PROPERTY name="start-sample-time-numeric" type="uint32" size="25" draw="false" sort="datetime" display-name="Start Sample Time">1373715002</PROPERTY>
<PROPERTY name="stop-sample-time" type="string" size="25" draw="false" sort="datetime" display-name="Stop Sample Time">2013-07-13 11:35:02</PROPERTY>
<PROPERTY name="stop-sample-time-numeric" type="uint32" size="25" draw="false" sort="datetime" display-name="Stop Sample Time">1373715302</PROPERTY>
</OBJECT>
<COMP G="0" P="2"/> <OBJECT basetype="controller-statistics" name="controller-statistics" oid="2" format="rows">
<PROPERTY name="durable-id" type="string" size="14" draw="true" sort="string" display-name="Durable ID">controller_B</PROPERTY>
<PROPERTY name="cpu-load" type="uint32" size="10" draw="true" sort="string" display-name="CPU Load">1</PROPERTY>
<PROPERTY name="power-on-time" type="uint32" size="22" draw="true" sort="string" display-name="Power On Time (Secs)">6376152</PROPERTY>
<PROPERTY name="write-cache-used" type="uint32" size="18" draw="false" sort="string" display-name="Write Cache Used">2</PROPERTY>
<PROPERTY name="bytes-per-second" units="KB" type="string" size="18" draw="true" sort="string" display-name="Bytes per second">484.3KB</PROPERTY>
<PROPERTY name="bytes-per-second-numeric" type="uint32" size="18" draw="true" sort="string" display-name="Bytes per second">484352</PROPERTY>
<PROPERTY name="iops" type="uint32" size="16" draw="true" sort="string" display-name="IOPS">35</PROPERTY>
<PROPERTY name="number-of-reads" type="uint64" size="16" draw="true" sort="string" display-name="Number of Reads">450040354</PROPERTY>
<PROPERTY name="read-cache-hits" type="uint64" size="16" draw="false" sort="string" display-name="Read Cache Hits">6610002098</PROPERTY>
<PROPERTY name="read-cache-misses" type="uint64" size="16" draw="false" sort="string" display-name="Read Cache Misses">882864162</PROPERTY>
<PROPERTY name="number-of-writes" type="uint64" size="16" draw="true" sort="string" display-name="Number of Writes">27971020</PROPERTY>
<PROPERTY name="write-cache-hits" type="uint64" size="16" draw="false" sort="string" display-name="Write Cache Hits">452666373</PROPERTY>
<PROPERTY name="write-cache-misses" type="uint64" size="16" draw="false" sort="string" display-name="Write Cache Misses">165556897</PROPERTY>
<PROPERTY name="data-read" units="GB" type="string" size="16" draw="true" sort="string" display-name="Data Read">4509.2GB</PROPERTY>
<PROPERTY name="data-read-numeric" type="uint32" size="16" draw="true" sort="string" display-name="Data Read">4509204959232</PROPERTY>
<PROPERTY name="data-written" units="GB" type="string" size="16" draw="true" sort="string" display-name="Data Written">413.7GB</PROPERTY>
<PROPERTY name="data-written-numeric" type="uint32" size="16" draw="true" sort="string" display-name="Data Written">413791386624</PROPERTY>
<PROPERTY name="reset-time" type="string" size="25" draw="true" sort="datetime" display-name="Reset Time">2013-04-30 16:25:55</PROPERTY>
<PROPERTY name="reset-time-numeric" type="uint32" size="25" draw="true" sort="datetime" display-name="Reset Time">1367339155</PROPERTY>
<PROPERTY name="start-sample-time" type="string" size="25" draw="false" sort="datetime" display-name="Start Sample Time">2013-07-13 11:30:02</PROPERTY>
<PROPERTY name="start-sample-time-numeric" type="uint32" size="25" draw="false" sort="datetime" display-name="Start Sample Time">1373715002</PROPERTY>
<PROPERTY name="stop-sample-time" type="string" size="25" draw="false" sort="datetime" display-name="Stop Sample Time">2013-07-13 11:35:02</PROPERTY>
<PROPERTY name="stop-sample-time-numeric" type="uint32" size="25" draw="false" sort="datetime" display-name="Stop Sample Time">1373715302</PROPERTY>
</OBJECT>
<COMP G="0" P="3"/> <OBJECT basetype="status" name="status" oid="3">
<PROPERTY name="response-type" type="string" size="12" draw="false" sort="nosort" display-name="Response Type">Success</PROPERTY>
<PROPERTY name="response-type-numeric" type="uint32" size="12" draw="false" sort="nosort" display-name="Response Type">0</PROPERTY>
<PROPERTY name="response" type="string" size="180" draw="true" sort="nosort" display-name="Response">Command completed successfully. (2013-07-13 11:35:02)</PROPERTY>
<PROPERTY name="return-code" type="sint32" size="15" draw="false" sort="nosort" display-name="Return Code">0</PROPERTY>
<PROPERTY name="component-id" type="string" size="80" draw="false" sort="nosort" display-name="Component ID"></PROPERTY>
<PROPERTY name="time-stamp" type="string" size="25" draw="false" sort="datetime" display-name="Time">2013-07-13 11:35:02</PROPERTY>
<PROPERTY name="time-stamp-numeric" type="uint32" size="25" draw="false" sort="datetime" display-name="Time">1373715302</PROPERTY>
</OBJECT>
</RESPONSE>
[/code]
Any help will be appreciated.
Thanks
Martin
how to remove spaces from text?
Hi,
this command write all servers name into TXT file, the problem that after every name the command add blank spaces, how can I remove them?
Get-ADComputer -Filter {OperatingSystem -Like "Windows *Server*"} -Property * | Format-Table Name -Wrap -Auto| out-file c:\servers.txt
Thanks
Lior
Single Symlink to multiple directories.
Hello,
I have been battling with an issue for the last week and thought I would post here for some help.
Some background:
We have users who use subversion.
However some users have their subversion linked on different drives.
Our users work with files that require dependencies also linked in the repository.
So if someone works and commits a file based on "C:\", a user with svn on "D:\" would have the file looking for the dependency in "C:\" which obviously doesn't exist.
I want to create a solution where I can create a universal drive map to "S:" that everyone can use in the future.
Creating a symlink C:\Repository <===> D:\Repository would not be an issue. What complicates this for me is that users will be working on more than a single project at a time and sometimes have repositories across multiple drives.
Ideally I would like to create a symlink like so, C:\Repository <===> D:\Repository + E:\Repository or what ever the case may be.
The problem:
Is there a way to do this? Create a single symlink to multiple locations.
The other method I have tried is using windows libraries but mapping these seems troublesome and it would be more coding for the same result.
I hope this makes sense, it is my first time using this forum.
Any help would be appreciated .
Thanks.
replace characters in string
Hi, I have a text file that contain list of folders in servers like this:
server1 c:\ora\oracel\
server2 d:\root\oracle\
server3 e:\Apps\LApps\oracle\
and so on,
I need to change every line to:
\\server1\c$\ora\oracel\
\\server2\d$\root\oracle\
\\server3\e$\Apps\LApps\oracle\
I tried to do it with replace command but I can't get the the result.
I appreciate the help with this issue.
Thanks
Creating Home Drives Based on group Membership
Ok what I am trying to do is create a script that will allow our Help Desk to create Home Directories on the many file servers we have around our organization. The problem is these file servers are a mix of mostly 2008R2 some 2012, some 2012R2 and even a couple of 2003R2 servers.
We have our users in AD groups and based on the AD Group membership that determines where their home drives are setup and they are mapped to.
So for example
UserA is a member of svr-1 in AD and has a share on \\server1\UserA$
UserB is a member of svr-2 in AD and has a share on \\server2\UserB$
UserC is a member of svr-3 in AD and has a share on \\server3\UserC$
Depending on where the users are working is usually the determining factor on where they are setup.
What I am trying to figure out is a way to script this out so that it will check AD for the membership and then compare that membership to the list of possible memberships available.
What I was thinking was something similar to this but if you have a user with a large group of memberships your going to have a lot of data plus the script would then have to parse the data in order to find the svr-1 for example as the output looks like CN=Svr-1,CN=Users,DC=domain,DC=local
$username=Read-Host 'What is the Login ID?'
([adsisearcher]"name=$username").FindAll().properties.memberof
Is there a simple way of doing this or canned script already out there that will make this job a lot easier??
How to put two elements of a array in one string
Hi,
Powershell is giving me a headache today. I need to create a text file (or PDF) and write 6 array's so that there are two arrays next to eachother, and that 3 times. Like this:
TITLE
Array1 Array2
abc , 15 hdu , 6
slt , 11 sky , 9
Array3 Array4
And so on, what ever I try powershell writes the first element of array1, goes to the next line and writes the first element of array2. Or first array1 and then Below, the next arrays. like:
abc , 15 < first array
hdu , 6 < second array
or:
array1
array2
array3
and so on.
All the array's have the same size and I need to "format" some text into the output as well like the title above the arrays.
Any help would be appriciated.
Robbert.
Find ad user witch email not equal UPN
How can i find AD user witch email address not equal UPN?
I try Get-ADUser -Filter { mail -notlike "UserPrincipalName" } but reasults are strange :(
AD "clean-up" scripts
I'm trying to create (if one doesn't already exist) a couple of PS scripts.
1.) Recurse the home directory folders on the server (i.e., \\server_name\share\jsmith , \\server_name\share\tjones etc.) and look for that account in AD. If there's no account in AD, delete the home folder
2.) Script to take input for the AD account to delete and then follow up by deleting the home folder.
Any suggestions on how to start and/or has anyone seen any scripts like this?
Thank you,
Ed
Automated install of SQL Server, Workflows or DSC???
Hey all,
Trying to improve my installs of sql server by automating it all with powershell.
i had a basic idea of
- running a bunch of checks before install, setting up things (format drives, create folders, add service account to local security)
- then running an install / slipstream (use a config file).
- then running the standard post install scripts to configure the instance (create maintenace plans, add standard extra accounts, monitoring etc).
So far im coming up with a lot of issues for keeping this simple..
namely. things like
to add a domain account to a local security group i need to turn off UAC. (Which needs a reboot)
Ive got a check to see if a reboot is needed (Our server team like to patch and not reboot!) but again if i reboot im starting from scratch again and re-running the script..
Looking at it. Workflows and DSC seem to be the answer. I was originally thinking DSC but i need to do so many checks before the install part.. Im starting to think workflows is more whats needed?!....
I've never done any work with either and maybe im running to buzz words for solutions? .. does anyone have any experience using either of them for there install builds? maybe not specific to SQL install but something else
Any suggestions or input would be greatly appreciated!
S
Checking that a file backed up to the NAS exists
I have a backup powershell script that copies files from the server to our NAS, which is remotely located with a login. I am writing a powershell script to check that the file has been backed up, but I'm having trouble doing this with the credential part, since Test-Path credential option doesn't work, and invoke-command doesn't work without remote desktop, which the NAS doesn't have.
I was thinking of trying to use the New-PSDrive command somehow to check it, since that's what I used to get source and destination setup for the File-Copy, but I'm not familiar enough with the commands to figure out how to accomplish this.
This is how I did the copy:
New-PSDrive -Name source -PSProvider FileSystem -Root "$SourcePath" | Out-Null
New-PSDrive -Name target -PSProvider FileSystem -Credential $cred -Root "$DestPath" | Out-Null
Copy-Item -Path source:\$filename -Destination target:\VMs\$newDestFileOnly
Remove-PSDrive source
Remove-PSDrive target
Would I be able to do a Test-Path target:\VMs\$newDestFileOnly ? I've been trying to figure this out for a long time and haven't found any info online that was similar enough. So far I saw: http://stackoverflow.com/questions/21335134/how-to-test-writing-to-a-file-share-path-using-credential
Any help would be greatly appreciated.
Extract characters from string starting at the end
Hello all,
I am trying to write a script to update our home-drives in AD to a new location but I need the last part of the string not including the first back-slash, like this:
\\servername\users$\myusername
I would like to store the myusername part in a variable so that I can use it to construct the new home-drive location:
\\newserver\users$\myusername
Please could I have some assistance.
Thanks very much. This is what I have produced so far:
#Add snap-in and connect to domain
Add-PSSnapin Quest.ActiveRoles.ADManagement | Out-Null
Connect-QADService 'domain.co.uk' | Out-Null
#Get users with home drive we wish to change
$Users = Get-QADUser -SizeLimit 0 -SearchRoot 'DC=domain,DC=co,DC=uk' -SearchScope Subtree | Where {$_.HomeDirectory -like '\\servername*'}
#Go through each user, setting new home drive
ForEach($User in $Users)
{
$OriginalHomeDrive = $User.homeDirectory
#Split $OriginalHomeDrive to just username ???
$SAMAccountName = $User.SAMAccountName
Set-QADUser -Identity $SAMAccoutName -HomeDrive "M:" -HomeDirectory "\\newserver\users$\$myusername" -proxy -whatif
}
Change print que's settings
Hi
I have this script I found on the web to batch install printers
Working great ( server 2008 )
But i want do add default settings as greyscale and duplex
is that possible and if so, how?
I Can live with if I have to run a seperat script to do this
the script Im using is as below
****
$printers = Import-Csv c:\printers.csv
function CreatePrinterPort
{
$server = $args[0]
$port = ([WMICLASS]"\\$server\ROOT\cimv2:Win32_TCPIPPrinterPort").createInstance()
$port.Name = $args[1]
$port.SNMPEnabled = $false
$port.Protocol = 1
$port.HostAddress = $args[2]
$port.Put()
}
function CreatePrinter
{
$server = $args[0]
$print = ([WMICLASS]"\\$server\ROOT\cimv2:Win32_Printer").createInstance()
$print.drivername = $args[1]
$print.PortName = $args[2]
$print.Shared = $true
$print.Sharename = $args[3]
$print.Location = $args[4]
$print.Comment = $args[5]
$print.DeviceID = $args[6]
$print.Rawonly = $true
$print.DoCompleteFirst = $true
$print.Put()
}
foreach ($printer in $printers)
{
CreatePrinterPort $printer.Printserver $printer.Portname $printer.HostAddress
CreatePrinter $printer.Printserver $printer.Driver $printer.Portname $printer.Sharename $printer.Location $printer.Comment $printer.Printername
}
Trim data from CSV file after a Special Character
Hi Everyone,
I am trying to read data from csv file i am using Import-csv cmdlet. this csv file has SQL Server data with instance names as below
Instance
Test
Test1\002
Test2
Test3\001
I want to trim the instance name and read only server name from the csv file. Looking for help for achieving this.
I am preparing a report with the details of the SQL Server services:
my script is as foillows
$InputFile = Import-Csv "C:\Test\SQLInstance.csv"
foreach($Servers in $Inputfile)
{
Write-Host "ServerName:" $Servers.instance
Get-WmiObject win32_service -ComputerName $Servers.instance | Select Name, Startmode, State | Where-Object `
{$_.name -like "*SQL*" -and $_.Startmode -match "Auto" -and $_.state -match "Stopped"} | FT -AutoSize
}
compare-object output not wanted
I am comparing two csv files and I noticed it was reading the line per line, which I did not want. I have figured out how to use the select -expand property in the compare-object import to help it find the difference in logonid vs doing line by line. MY issue is once a logon id is found I want to output all the other colums that are associated with the logonid to my log file. How can I do that. Below is a sample and it works if I allow a line by line but I need to filter by logon id and when found output the whole row of info for that user How can I accomplish this. example of my input file. logonid name displayname and so on.
importFile1 = Import-Csv -Path $file1
$importFile2 = Import-Csv -Path $file2
$compareObj = compare-Object -ReferenceObject (import-csv -Path $file1 | select -expandProperty logonid) -DifferenceObject (Import-Csv -Path $file2 | select -expandProperty logonid)
foreach($conflict in $compareobj){
Write-Host $conflict
if($_.sideindicator -eq "=>"){
$ChangeFile = $file2Path
$note = "Looks Like Addition to the Group has occurred"
}
else{
$ChangeFile = $file1Path
$note = "Looks Like an Object was removed from this group"
}
New-Object -TypeName PSCustomObject -Property @{
LogonID = $conflict.inputobject.logonid
Name = $conflict.inputobject.name
DisplayName = $conflict.inputobject.displayname
AccountDisabled = $conflict.inputobject.AccountDisabled
GroupName = $conflict.inputobject.groupname
NestedMember = $conflict.inputobject.nestedmember
GroupEmpty = $conflict.inputobject.GroupEmpty
ParentGroup = $conflict.inputobject.ParentGroup
ConflictFile = $ChangeFile
Note = $note
} | select-object LogonID,Name,Displayname,AccountDisabled,GroupName,NestedMember,GroupEmpty,ParentGroup,ConFlictFile,Note | Export-Csv $LogFile -Append -NoTypeInformation
}
}
Update PoSH from v2 to v4 and Continue Script?
Hi all;
I'm in process of developing a script for field techs that will handle a lot of the tedium (and user error-prone processes) involved in setting up a new computer for (a) client(s).
It's fairly basic so far (changes time zone, sets up local admin/pass, tweaks the firewall, etc), but recently ran into an issue where Lenovo sent a Windows 7 machine with v2 on it which meant half of the script didn't run at all. Turns out they do this fairly regularly.
So, what I'm trying to figure out is how I can get the script to update to Framework v4, reboot, and continue on it's merry way. Looks like Workflows may be the answer, but then that's in v3, not v2 so . . . no go.
Any thoughts or tricks on how to get this done?
Thanks!
Finding the number(.count) of passwords
Iwant to find outhow manyusersare using the defaultpassword has not been.
the default passwordis called"Password"
can youhelp me here?
Greetingsfrom theWorld ChampionCountry
Marek
List of all GPO's with their links.
I'm brand new to PS, and have tried using the various helps for both the Get-ADOrganizationalUnit and Get-GPO cmdlets, but I can't seem to get what I need. I found a script from Jaap in another post ( http://powershell.com/cs/forums/p/13834/25908.aspx ) which (I export to a CSV and…) lists all the OU's in column A, and then the GPO's linked to each of the OU's. However, what I want is just the opposite. I want to get a list of all the policies in column A, and then all the OU's that they're linked to in column B.
Column A (GPO's) Column B (Linked to...)
IESettingsGPO1 LondonOU, ChicagoOU, AtlantaUsersOU
RemoteUsersGPO2 ChicagoOU
GPO3 domainlevelOU
etc...
On the PS.org forum, I was directed to the Get-GPLink and SDM-GP cmdlets, but I'm not sure if those produce the output I need. So far, I can use the cmdlet below to get a list of all the GPO's, but I don't know how to pipe that over to some other command to be able to get the links to each of the GPO's
get-gpo -All | Select-Object displayname | format-list
Thanks.
Disable AD Computer from txt file and move it to target OU
This is the script I have, but something is not right.
Import-Module ActiveDirectory
$computers = get-content "C:\disabled computer.txt"
foreach-object{
$computer | disable-adaccount
$computer | move-adobject -targetpath "ou=Disabled computers,dc=Domain,dc=com"
write-host “$computer will be moved to Disabled Computer OU”
}
Anyone can help?
Thanks