Modifying XML Contents based on a configuration.
Hi Folks,
I am new to powershell scripting, I am trying to explore an idea of automating the scheduled task based on a configuration.
The input file will be an scheduled task xml and the configuration xml.
To modify the schedule task xml and start a task, I am exploring two options.
1. Parse the task xml and update fields with new values as per the configuration xml.
2. Create an object from the task xml and modify the members of the object and create the new xml with the modified object.
The second one looks more scalable but couldn't get hold of any commandlet/function to create an object from the xml file.
Can you folks give some suggestions?
Thanks.
- Changed type Bill_Stewart Friday, February 17, 2017 4:32 PM
Reply:
[xml]$task=Get-Content sometask.xml
\_(ツ)_/
------------------------------------
Reply:
[xml]$task = Export-ScheduledTask -TaskPath \Mytasks2\ -TaskName MyTask4 D:\scripts> $task.Task.Actions Context Exec ------- ---- Author Exec D:\scripts> $task.Task.Actions.Exec Command Arguments WorkingDirectory ------- --------- ---------------- powershell -NoExit -File TEstarray.ps1 -D 1,2,3 d:\scripts
\_(ツ)_/
------------------------------------
Reply:
Thanks jrv. It's really helpful.
Now I am creating a XML config file, but I want to validate it against a schema. Is there any ways it can done?
I have seen Test-XML being recommended in online, but I don't see this cmdlet in powershell v5.0.
I am considering to write code to validate it on each node? Is this is a good start?
Please share your thoughts
- Edited by komal436 Friday, December 23, 2016 12:17 PM
------------------------------------
Reply:
Add a schema reference to the XML before you start adding nodes.
http://www.w3schools.com/xml/schema_howto.asp
The scheduler XML has a schema reference.
<?xml version="1.0" encoding="UTF-16"?> <Task version="1.3" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"> <RegistrationInfo> <Date>2016-07-13T17:28:25.543672</Date> <Author>BOONDOCK\jsmith</Author> <URI>\Mytasks2\MyTask3</URI> </RegistrationInfo> <Triggers> <CalendarTrigger> <StartBoundary>2016-12-23T02:13:57</StartBoundary> <EndBoundary>2017-12-23T02:13:58-05:00</EndBoundary> <Enabled>true</Enabled> <ScheduleByDay> <DaysInterval>1</DaysInterval> </ScheduleByDay> </CalendarTrigger> </Triggers> <Principals> <Principal id="Author"> <UserId>S-1-5-21-1990907114-190243296-4277213585-1001</UserId> <LogonType>InteractiveToken</LogonType> <RunLevel>LeastPrivilege</RunLevel> </Principal> </Principals> <Settings> <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy> <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries> <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries> <AllowHardTerminate>true</AllowHardTerminate> <StartWhenAvailable>false</StartWhenAvailable> <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable> <IdleSettings> <StopOnIdleEnd>true</StopOnIdleEnd> <RestartOnIdle>false</RestartOnIdle> </IdleSettings> <AllowStartOnDemand>true</AllowStartOnDemand> <Enabled>false</Enabled> <Hidden>false</Hidden> <RunOnlyIfIdle>false</RunOnlyIfIdle> <DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession> <UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine> <WakeToRun>false</WakeToRun> <ExecutionTimeLimit>PT72H</ExecutionTimeLimit> <Priority>7</Priority> </Settings> <Actions Context="Author"> <Exec> <Command>powershell</Command> <Arguments>-NoExit -File TEstarray.ps1 -D 1,2,3</Arguments> <WorkingDirectory>d:\scripts</WorkingDirectory> </Exec> </Actions> </Task>
This is the schema reference: xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"
If you add or change anything that violates the referenced schema the XML class will throw an error.
\_(ツ)_/
- Edited by jrv Friday, December 23, 2016 12:23 PM
------------------------------------
conditional split to flat file
Hi All,
Can any one suggest how to create a package using conditional split to Flat file and OLE DB Destination.
I have
Source OLE DB table T1 ->Conditional Split (Case 1 with col1 =="A",Case 2 with col2=="B")
->Case 1 connected to OLE DB Destination table T2
->Case 2 is Flat File .I don't know
getting error
Error at Conditional Split [Flat File Destination [221]]: The data type for "Flat File Destination.Inputs[Flat File Destination Input].Columns[SalesTerritoryImage]" is DT_IMAGE, which is not supported. Use DT_TEXT or DT_NTEXT instead and convert the data from, or to, DT_IMAGE using the data conversion component.
Error at Conditional Split [SSIS.Pipeline]: "Flat File Destination" failed validation and returned validation status "VS_ISBROKEN".
Error at Conditional Split [SSIS.Pipeline]: One or more component failed validation.
Error at Conditional Split: There were errors during task validation.
(Microsoft.DataTransformationServices.VsIntegration)
Thanks
Ipsita
- Changed type Ipradhan Thursday, December 22, 2016 1:44 PM
Reply:
You need help in finding the case logic or in fixing the error?
The error says that, it is not possible to export the image data that you have in Column - SalesTerritoryImage.
So before Flat File Destination, have Data Conversion task and convert this column to DT_TEXT OR DT_NTEXT.
Optionally in Source query at OLEDB Source, you can convert the Column data type.
SELECT CONVERT(varchar(max),CONVERT(varbinary(max),[SalesTerritoryImage]),2)FROM SomeTable;
Cheers
Vaibhav
MCSA (SQL Server 2012)
------------------------------------
Reply:
------------------------------------
Reply:
Hi,
For this you can simply use a data conversion transformation in the case2 data flow path which is going to the flat file destination. As you can not pass a DT_IMAGE type data as it is to a flat file, convert it to DT_TEXT using data conversion task and you will be able to write the data to flat file. Following are the screenshots of the package I tested with the similar scenario.
ApoorvaW
- Edited by ApoorvaW Thursday, December 22, 2016 4:49 PM
------------------------------------
Reply:
------------------------------------
Skype For Business
how to integrate with sharepoint on permisses and skype for business on permisses .
I am very new to this domain so please tell me clearly
Reply:
Here you go Detailed document
https://www.microsoft.com/en-us/download/details.aspx?id=39616
Remember to mark as helpful if you find my contribution useful or as an answer if it does answer your question.That will encourage me - and others - to take time out to help you Check out my latest blog posts on http://exchangequery.com Thanks Sathish (MVP)
------------------------------------
Reply:
Hello Surendar,
The presence information is picked up via the Office package on the client side. there isn't much integration between SP and skype for Business and notmally the skill search. Should work automatically, The link which Sathish shared should help
Linus || Please mark posts as answers/helpful if it answers your question.
------------------------------------
Reply:
IF my site host and people search center is working then skype for business will get inteact automatically
i fixed with this .. it is working for me
- Edited by Surendar Kani Thursday, December 8, 2016 8:59 AM
------------------------------------
Reply:
If you are talking about the SharePoint Skill search you need to do modify your client policy:
Set-CSClientPolicy -identity global –SPSearchInternalURL .<domain>/_vti_bin/search.asmx">http://<server>.<domain>/_vti_bin/search.asmx
Set-CSClientPolicy -identity global –SPSearchCenterInternalURL .<domain>/SearchCenter/Pages/PeopleResults.aspx">http://<server>.<domain>/SearchCenter/Pages/PeopleResults.aspx
I recommend to check the URL in the browser first. Now you can use the SharePoint skill search in your SfB client. You Need to logout and login again.
------------------------------------
Reply:
- configuration of mysite host------------------------- 9
- configuration of search center--------------------18
- configuring people serach center---------------- 23
- crawling----------------------------------------------------------- 28
------------------------------------
Reply:
------------------------------------
Reply:
Hi Joerg,
for integrating skype for business with sharepoint, we have to configure all those things in my last post ,
then it will automatically get integarted. and then it will show presence.
Thanks ANd Regards
Surendar S
-----------------------------
Please mark posts as answers/helpful if it answers your question. AND HELP ME TO INCREASE MY POINTS
------------------------------------
forget admin account user password
I want to install some program into my computer but i cannot because i forget passwords of admin user account. what should i do to recover or reset the password?
Looking forward for your answer.
Thanks,
Rachana
Reply:
Hi,
These articles may help you, please refer to the links:
"How to Reset Your Forgotten Windows Password the Easy Way":
http://www.howtogeek.com/96630/how-to-reset-your-forgotten-windows-password-the-easy-way/
"If you forget your Windows admin password, try this":
http://www.pcworld.com/article/2988539/windows/if-you-forget-your-windows-admin-password-try-this.htmlOtherwise you can try with Hirens Boot CD (you have to create a CD/DVD/USB Booting, see help on website): http://www.hirensbootcd.org/resetting-windows-password/
Please Note: Since the websites are not hosted by Microsoft, the links may change without notice. Microsoft does not guarantee the accuracy of this information.
_____________________________________
Please mark the reply as an answer if you find it is helpful.
------------------------------------
Regional settings and time format issue in Windows 10 1607 with MDT integration
CM 1610, MDT 8443, Windows 10 CB 1607, using UDI pages. Even if location is set right in UDI, time format still display wrong and "match windows display language" is selected by default after fresh installation. If I manually change it to Finland, then it would be okay, but I need that to be automated with UDI.
This issue is seing only with Windows 10. If I change Windows 7 to the same TS, using same UDI, time format will stand correctly. Any ideas?
- Edited by Pavel yannara Mirochnitchenko Wednesday, December 21, 2016 10:17 AM
Reply:
------------------------------------
Reply:
------------------------------------
Reply:
------------------------------------
Unable to connect to a wireless network using command lines.
Hello,
I'm just trying to connect to a wireless profile that my system shows as available network and has been impossible. I'm following some of the steps Microsoft provides using 'netsh wlan' commands but no results at all.
For example: (all done in cmd lines)
My system shows me just one network interface even when I have two connected. (But this is not the main issue)
System shows me just one profile for that previous interface, even when in UI I can see 10 or more wireless network.
If I'm seeing a wireless named "my2nd" and I try to connect to it like this:
netsh wlan connect name="my2nd" interface="Wireless Network Connection"
Output says: There is no profile "my2nd" assigned to the specified interface.
Now, referencing the docs I shoud add the a new profile to that interface. But how can I build in code or something the .xml file to add it. How could I get the parameters or information needed to add a profile that represent an available network to my interface to connect to it after that. (Thinking on using these commands and methods in another programming language like Python)
Note: I also have noticed that some of the network have no profile name using ctypes (a python lib that load the function of wlanapi.dll)
If anyone could help me in this I'd be grateful.
Best regards,
D
- Edited by didzan Thursday, December 22, 2016 11:02 PM
Insider build 14986 ISO file is available to download
This is directly from Microsoft...........
Insider build 14986 ISO file is available to download
- Changed type david hk129 Thursday, December 22, 2016 10:32 PM
Reply:
------------------------------------
Reply:
, its a discussion!
just curious.
Why does it matter, Question or Discussion ?
If it has to do with "points", that's trivial.
We come to the forum to help others. If my some of replies manage to help others, that's my reward.
"Point reward" is irrelevant.
------------------------------------
Reply:
To me its down to the search in TechNet forums. Yes they are interesting to use but afaik the results favor questions. Sorry nothing meant by that I could have explain my comment better.
Plus perhaps I am too nerdy so a discussion to me!
------------------------------------
Issue with Powershell AD creation script
Script was working perfect in Windows 7 Pro using powershell to create accounts. Problem is when i upgraded my work machine to windows 10 script broke and im lost as to what is causing this. I realize this is saying that PrincipalsAllowedToDelegateToAccount is a null value and can't be copied but i don't understand where this value is. I had no issues running this script on windows 7 and have been using it for a few months now. Any help would be a lifesaver.
Thanks
empty, or an element of the argument collection contains a null value. Supply a collection that does not contain any
null values and then try the command again.
At C:\NewUserStuff\xxx-AD.ps1:97 char:13
+ $LikeUser | New-ADUser -Server "xxx-xxx-DC1.xxxxxxxxxx.local" -Sa ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (CN=Contractor T...aGroup,DC=local:PSObject) [New-ADUser], ParameterBinding
ValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.NewADUser
part of the script Line 84-97
84 $password = "Ppg" + $StartDate + "@"85 $dpassword = ConvertTo-SecureString -AsPlainText $password -force
86 $LikeUN = $LikeUser.DistinguishedName | Out-String
87 $LikeUser = Get-ADUser $LikeUserName -Server "xxx-xxx-DC1.xxxxxxxxxx.local" -Properties *
88 $DN = $LikeUser.DistinguishedName
89$OldUser = [ADSI]"LDAP://$DN"
90 $Parent = $OldUser.Parent
91 $OU = [ADSI]$parent
92 $OUDN = $OU.DistinguishedName
93 $domain = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
94 $NewName = "$firstname $lastname"
95 $UPN = $UserName+$UPN2
96 $LikeUN = $LikeUser.DistinguishedName | Out-String
97 $LikeUser | New-ADUser -Server "xxx-xxx-DC1.xxxxxxxxxx.local" -SamAccountName $UserName -Name $NewName - DisplayName $NewName -UserPrincipalName $UPN -GivenName $FirstName -Surname $LastName -Instance $DN -Path "$OUDN" -AccountPassword $dpassword -Company $LikeUser.Company -Department $LikeUser.Department -title $Title -OfficePhone $LikeUser.OfficePhone -Mobile $MobileNumber -Enabled $true
- Changed type Bill_Stewart Friday, February 17, 2017 4:30 PM
- Moved by Bill_Stewart Friday, February 17, 2017 4:30 PM This is not "fix/debug/rewrite my script for me" forum
Reply:
Please read the following post first. It is right at the top of this forum:
This forum is for scripting questions rather than script requests
-- Bill Stewart [Bill_Stewart]
------------------------------------
Reply:
The parameter you refer to, PrincipalsAllowedToDelegateToAccount, is new in PowerShell V4. The Set-ADUser help now refers to this parameter, but says that it is not required:
https://technet.microsoft.com/en-us/library/hh852287%28v=wps.630%29.aspx
But I don't see where the help for New-ADUser refers to this.
The following blog post discusses this:
https://blog.kloud.com.au/2013/07/11/kerberos-constrained-delegation/
I hope this helps.
Edit: This documentation for New-ADUser mentions the new -PrincipalsAllowedToDelegateToAccount parameter, but includes no additional information.
https://technet.microsoft.com/en-us/library/hh852238(v=wps.630).aspx
Edit: The issue must have something to do with constrained delegation and the msDS-AllowedToActOnBehalfOfOtherIdentity attribute (which is assigned a value by the -PrincipalsAllowedToDelegateToAccount parameter). These blog posts may help:
Richard Mueller - MVP Enterprise Mobility (Identity and Access)
- Edited by Richard MuellerMVP Thursday, December 22, 2016 8:49 PM added links
------------------------------------
Reply:
You cannot use a wild card when copying an instance. You must explicitly specify only properties that can be copied
$LikeUser = Get-ADUser jsmith -Properties City, PostalCode, OfficePhone $likeUser.DisplayName = 'test user1' New-AdUser -Instance $LikeUser -Name test1234 -SamAccountName test1234 -Path $oupath
You can directly assign most properties in the instance and use a "splat" to set the remainder.
$LikeUser = Get-ADUser jsmith -Properties City, PostalCode, OfficePhone $splat=@{ Name = 'test1234' SamAccountName = 'test1234' DisplayName = 'test user1' Path = $oupath Password = ConvertTo-SecureString -AsPlainText $password -force } New-AdUser -Instance $LikeUser @splat \_(ツ)_/
- Edited by jrv Thursday, December 22, 2016 10:27 PM
------------------------------------
How I could Preload a powershell.exe in memory and use it when needed ?
Hello,
I'm searching how I could improve my PowerShell GUI load time. For that, I'm thinking about launch a empty powershell.exe at the startup, for having it in memory.
The main idea, is when I need my GUI, I will use this preload powershell.exe to execute my GUI script.
Is there possible to do that ?
- Keep a powershell.exe in the process
- Send a script to this powershell.exe
- Edited by MrFlamby Thursday, December 22, 2016 3:10 PM
- Changed type Bill_Stewart Friday, February 17, 2017 4:30 PM
Reply:
Grüße - Best regards
PS:> (79,108,97,102|%{[char]$_})-join''
------------------------------------
Reply:
The biggest cause of slow load times with a form is what is in the form load event. Until the load event completes the form will not display.
To have the form display before it is loaded use the form "Activated" event which occurs after the form is displayed.
\_(ツ)_/
------------------------------------
Adding signatures to Outlook via GPO with vbs
SBS 2008 / basic antivirus solution (either free or cheap)
Hello,
Is there a free antivirus for SBS 2003 and SBS 2008 ?
If not free, then a cheap yearly license.
I want the basic protection only, no super duper firewall protection. For server only, not for client machines.
Something like Microsoft Security Essentials but for the server would be great.
Any ideas?
- Changed type Sean Zhu - Thursday, June 2, 2011 3:27 AM
Reply:
Larry Struckmeyer
Please post the resolution to your issue so that everyone can benefit
Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
------------------------------------
Reply:
Hello
I'm sorry i didnt reply before.
I'm running Untangle from http://www.untangle.com/ .
I understand what you say, but let's say a computer on the network gets infected (somehow) and then infects contents on the shared folders of the server. If the server is running its own antivirus, the infected files get detected and clean almost immediatly. No effort.
I'm still looking for a good solution for this.
------------------------------------
Reply:
Whats your opinion on
Kaspersky Security for File Server
http://www.kaspersky.com/kaspersky-security-file-server
Applications Inside
Applications inside Kaspersky Security for File Server:
------------------------------------
Reply:
an alternative, and I ask that you assess your situation before taking such alternative.
Microsoft Security Essentials is free for any use up to 10 clients.
the free MSE does not have a 'server' portion but I, and some few others, have _given up_ on server AV, relying instead on 'client protection'. 'front end, or edge, protection' makes such an even more attractive proposition.
When I recently told Trend that their WFBS product was causing more problems than it was curing I removed it from all systems on my LoungeAN, including the server which is still running 'naked'.
Worth thinking about?
------------------------------------
Reply:
Hi,
I've been doing exactly that. Running a client's SBS2008 naked.
But i'll explain why this worries me.
- It's a client server and I'm not there all the time
- Their resident IT guy who is not a very knowledgeable dude logs into the server from time to time (in case he needs to check something or make a restart)
- For some reason he might conect a flash drive to the server, this flash drive might be infected (very common these days).
- ...
- Disaster?!
------------------------------------
Reply:
really, if he's trusted enough to be allowed to signon to the server he should be aware of 'you don't click just any link from searches' or maybe 'there's actually no reason for you to run IE on the server, EVER'.
and 'you simply don't plug 'keys' into the server, EVER' and an explanation that the server is running 'naked' should be enough. 'If you want a file loaded on the server you put the CD, or USB key, into your workstation and copy the file from there to the server' (I normally have a 'computer maintenance' share on the server for just such purpose).
Even the CEO of the company doesn't 'own' the server, the company does. Anyone accessing the server has a obligation to act responsibly when directly logged on to the server.
or let 'em go for their life and charge like blazes for any fixes. They'll soon get the message.
------------------------------------
Reply:
www.clamwin.com
-WaltZ SETC, Inc.
------------------------------------
Improve Multicast WDS Transfer Speed
Do you have any tips / improvements for increasing the OS Multicast Speed?
Now, we can reach speeds between 80 to 100 Mbit/s.
There is much space from improvement, Server is connected with 2x1 Gbit/s (in a Trunk) and Clients are Dell Opliplex 9020 with 1 Gbit/s Network Connection.
The Servers CPU is on 10-20% utilization, Client is at 30%.
The Registry Key "ApBlockSize" is already set to 1373.
Reply:
- Edited by Amirhossein Karimpour Sunday, December 18, 2016 1:20 PM
------------------------------------
Reply:
------------------------------------
How to deploy Windows 8.1 RT System Recovery Image and WinRE to the recovery partition
Hi everyone,
I recently purchased a Dell Windows RT tablet from someone. It had the problem of not starting anymore. I managed to get my hands on a Windows RT 8.0 Recovery USB Image for this type of tablet. I used a Imaging tool to install this image on a USB drive. I booted with this and I could access the Advanced recovery options. I started the Command Prompt and launched Diskpart. I saw all of the partitions where gone. So I used Diskpart to re-install all of the partitions using the Microsoft standard. It looks like this:
convert gpt
create partition primary size=450
set id=DE94BBA4-06D1-4D40-A16A-BFD50179D6AC
gpt attributes=0x8000000000000001
format quick fs=ntfs label="Windows RE tools"
assign letter=T
create partition efi size=200
format quick fs=fat32 label="System"
assign letter=S
create partition msr size=128
create partition primary
shrink minimum=4200
gpt attributes=0x0000000000000000
format quick fs=ntfs label="Windows"
assign letter=W
create partition primary
set id=de94bba4-06d1-4d40-a16a-bfd50179d6ac
gpt attributes=0x8000000000000001
format quick fs=ntfs label="Recovery image"
assign letter=R
rescan
exit
All went well. After recreating the partitions, I used DISM to deploy the *.wim image on the USB drive to the Windows partition and installed the bootloader afterwards. The tablet was fixed after this :) I installed Windows RT 8.0 and updated to Windows 8.1 RT afterwards without problems :-).
So, this is great news. However, I would like to make sure there is a Full Recovery option available, which recovers the Tablet to Windows 8.1 RT when using the 'Refresh' option. I assume the Windows Installation and the 8.1 update doesn't create these Recovery files automatically on the Recovery Partition.
So my question is, how do I create a Windows RT 8.1 Recovery Image and deploy the Windows 8.1 RT Recovery files including the WinRE environment to the Recovery partition, so that in a case of a needed Refresh, Windows can fully refresh the tablet to it's factory defaults? I assume I first need to create a Recovery Image and then use DISM again to deploy the Recovery files to the correct partition and folders? Only, I have no idea how to do this.
Any help is greatly appreciated.
Kind regards,
Rob, the Netherlands.
- Changed type kelvin_hsu Friday, December 6, 2013 2:07 AM Windows RT Product
Reply:
Hi,
Considering that the issue should be related to Windows RT, and Since we have limited testing environment, I suggest you submit a new case on Windows RT forum as they will be more professional on your issue:
This is the Windows RT forum link.
http://answers.microsoft.com/en-us/windows/forum/windows_rt?auth=1
The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.
Regards,
Kelvin hsu
TechNet Community Support
------------------------------------
Reply:
I found this on you tube this should help.
https://www.youtube.com/watch?v=GSfezTi44_w
------------------------------------
Microsoft Test Manager
Is anyone else having problems with their desktop icons being moved, when you run tests in Microsoft Test Manager? If so, is there a way to stop it from doing that?
Thanks!
Reply:
the reason the ICONS shift is do the test running on the GUI frame
you can use the tool located in Program Files (x86)\Windows Kits\10\bin\x64\Inspect application
to see how everything correlate's with in the GUI FRAME some of the tools may cause radical behavior in some older model computers from the 686 class or lower I wouldn't worry about it just move them back or use the refresh left click utility
------------------------------------
VB Script assistance
I have the following script, but I would like to also include IP Address and MAC. This outputs to a csv. I would appreciate any assistance.
Option Explicit
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
Const PATH_TO_INPUT = "Computers.txt"
Const PATH_TO_OUTPUT = "MachineInventory.csv"
Dim fso
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
Dim shl
Set shl = WScript.CreateObject("WScript.Shell")
Dim input
Set input = fso.OpenTextFile(PATH_TO_INPUT)
Dim output
Set output = fso.CreateTextFile(PATH_TO_OUTPUT, True)
output.WriteLine "Hostname,Serial Number,Make,Model,BIOS Version,Operating System,CPU,Memory (MB),Disk Drives"
Dim wmiService
Dim wmiResults
Dim hostname
Dim make
Dim model
Dim biosversion
Dim operatingSystem
Dim serialNumber
Dim cpu
Dim memory
Dim drives
Dim line
Dim exec
Dim pingResults
While Not input.AtEndOfStream
line = input.ReadLine
hostname = ""
make = ""
model = ""
biosversion = ""
operatingSystem = ""
serialNumber = ""
cpu = ""
memory = ""
drives = ""
Set exec = shl.Exec("ping -n 2 -w 1000 " & line)
pingResults = LCase(exec.StdOut.ReadAll)
If InStr(pingResults, "reply from") Then
WScript.Echo "Reply From: " & line
On Error Resume Next
Set wmiService = GetObject("winmgmts:\\" & line & "\root\CIMV2")
If Not Err.Number = 0 Then
output.WriteLine line & ",Error: " & Err.Description
WScript.Echo line & ",Error: " & Err.Description
On Error GoTo 0
Else
On Error GoTo 0
hostname = line
Set wmiResults = wmiService.ExecQuery("SELECT * FROM Win32_BIOS", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
Dim item
For Each item In wmiResults
serialNumber = Trim(item.SerialNumber)
biosversion = Trim(item.SMBIOSBIOSVersion)
Next
Set wmiResults = wmiService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each item In wmiResults
make = Trim(item.Manufacturer)
model = Trim(item.Model)
Next
Set wmiResults = wmiService.ExecQuery("SELECT * FROM Win32_OperatingSystem", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each item In wmiResults
operatingSystem = Trim(item.Name)
operatingSystem = Split(operatingSystem, "|")(0)
memory = Round(Trim(item.TotalVisibleMemorySize) / 1024, 2)
Next
Set wmiResults = wmiService.ExecQuery("SELECT * FROM Win32_Processor", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each item In wmiResults
cpu = Trim(item.Name)
Next
Set wmiResults = wmiService.ExecQuery("SELECT * FROM Win32_LogicalDisk WHERE DriveType=3", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each item In wmiResults
drives = drives & Trim(item.DeviceID) & " " & Round(Trim(item.Size) / (1024^2), 2) & ";"
Next
output.WriteLine hostname & "," & serialNumber & "," & make & "," & model & "," & biosversion & "," & operatingSystem & "," & cpu & "," & memory & "," & drives
WScript.Echo hostname & "," & serialNumber & "," & make & "," & model & "," & biosversion & "," & operatingSystem & "," & cpu & "," & memory & "," & drives
End If
Else
output.WriteLine line & ",No Response"
WScript.Echo line & ",No Response"
End If
Wend
output.Close
input.Close
Set wmiService = Nothing
Set wmiresults = Nothing
Lee Mossolle
- Edited by lmossolle Thursday, December 22, 2016 2:29 PM updated
- Changed type Bill_Stewart Friday, February 17, 2017 4:24 PM
- Moved by Bill_Stewart Friday, February 17, 2017 4:25 PM Help vampire
Reply:
Please read the following post first. It is right at the top of this forum:
This forum is for scripting questions rather than script requests
-- Bill Stewart [Bill_Stewart]
------------------------------------
Standard for commenting enhanced SQL Server Stored Procedures
Just wondering what y'all do for commenting SQL Server Stored Procedures for enhancements. Not only comment blocks at the top of the SQL Server Stored Procedure but if y'all comment within the SQL Server Stored Procedure itself in terms of identifying the specific enhancement line with a date and initials of the developer, etc..
We are trying to invoke some standards and we're looking for what people do and what best practices might be.
Thanks for your review and am hopeful for a reply.
Reply:
Good question!
I normally only have few lines with comments at the top and add Modified by .. date in that block.
I may include some comments inside the procedure but normally don't put date and initials for in-line comments.
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles
------------------------------------
Reply:
I agree with Naomi.
Enhancement/update comments should be at the sp header comment block. The reasoning is to keep the sp easy to read.
If you need sp update history, use a source-code version control system.
Kalman Toth Database & OLAP/AI Architect SQL Server 2016 Database Design
New Book : Beginner Database Design & SQL Programming Using Microsoft SQL Server 2016
------------------------------------
SharePoint Question
Hello,
I wanted to know if this is standard SharePoint feature or something is wrong with our install. For a document library, the last modified date only shows the day and month and doesnt show year for the current year but if there is a file modified last year then we get day,month and year?
Reply:
HI,
The date formats SharePoint 2013?
You can change them back to the old format. Go to the column settings and tweak the Display Format to the one you prefer, (and do this for any new date column you create) :


Cheers,
Ivan
SharePoint Developer / MVP 2010 – 2015
Blog: http://blogs.msmvps.com/ivansanders/
-Ivan
------------------------------------
Powershell to grab ADGroups, members, then NTFS Permissions on shares
Hi,
Relatively new to powershell and its concepts but learning as I go.
Im currently evaluating a number of legacy file servers as we are looking forward to a building move as well as new hardware in "the new world". Part of this is to evaluate both our AD Groups which there is a lot of dead weight in, as well as later on, windows file server shares which I can cross check access against this list to allow us to drop old shares and delete no longer needed groups etc. (This is an estate which hasnt really had any housekeeping for around 10 years, just had several waves of consolidation as companies have been merged...
With this bit of powershell Im trying to generate a report of sorts.
Listing 1 row for each AD Group, a count of members, the number of inactive(disabled accounts) members, and a list of users/groups in each group. I can then port this into a spreadsheet and start filtering etc.
e.g.
GROUP, Member Count, Inactive Count, Members:
Infrastructure Team, 7, 5, "Bjones, BDavies, Jsmith, Kbarlow, Sappleton, Pdint, Rwright, Amarkam"
I guess the following Powershell is heading in the right direction but I know this can be done it ma much cleaner way.
Any input or guidance would be great! :)
CODE:
# Get the list of SECURITY-GROUPS from AD (Domain not specified as local machine and logged in user are both domain members of the domain being queried. $SecurityGroups = get-adgroup -filter {groupcategory -eq "security" } | select samaccountname | sort samaccountname $SecurityGroups | ft write-host TOTAL GROUPS : $SecurityGroups.count # Work through the list of groups to identify members and count of members (and inactive members) foreach ($SecurityGroup in $SecurityGroups) { $name=$SecurityGroup.samaccountname $members = get-adgroupmember -identity $name $Membercount = $members.count # $userdisabled = $members | where {$_.Enabled -eq $false} $DisabledCount = $userdisabled.count # Check that there are members before trying to process data on them if ($Membercount -gt 0) { [int]$Inactivemembers = 0 # Work through each group processing members one at a time foreach ($member in $Members) { $userdisabled = "" #Im sure I can do the following command as a single command without the loop to count the disabled accounts in the group... but for now this will do... [array]$userdisabled = Get-ADUser -filter {samaccountname -eq $member.samaccountname -and Enabled -eq $false} if ($userdisabled.enabled -eq $false) { $Inactivemembers += 1 } } } Many thanks
- Edited by Dustynet Thursday, December 22, 2016 7:44 AM insert code block
- Changed type Bill_Stewart Friday, February 17, 2017 4:24 PM
Reply:
Could you please format your code as code in the future here in the forum?
Your request is too unspecific? Do you get some errors? Or do you get other than the expected results? Or do you have a particular question to a particular snippet of code then you should ask this.
Grüße - Best regards
PS:> (79,108,97,102|%{[char]$_})-join''
- Edited by BOfH-666 Friday, November 25, 2016 3:40 PM
------------------------------------
Reply:
Your request doesn't make much sense or seem very useful but here:
get-adgroup -filter { groupcategory -eq "security" } | Get-AdGroupMember | where{ $_.objectClass -eq 'user' } | Get-Aduser | Group Enabled | Select @{n='Enabled';e={$_.Name}}, Count \_(ツ)_/
------------------------------------
Reply:
Thanks for the response.
Your condensed PS takes a long time to complete, due to the call after call for AD data.
I was looking for something quicker in processing time and came up with the idea of querying ADUsers and ADGroups (both relatively quick queries in themselves), then proccessing in memory.
This resulted in the following code which produces the output I was looking for. Specifically, something useful for generating a report which I can save to Excel, then use for AD housekeeping.
This is useful as it clearly identifies groups with no members, groups with volumes of disabled accounts, security groups with email addresses etc which can all be reviewed and managed accordingly.
# THIS SCRIPT MUST BE RUN AS ADMINISTRATOR import-module activedirectory clear-host # ------------------------------------------------- # Check if we can write output files to the desktop # ------------------------------------------------- #$outputfile1 = "$env:userprofile\desktop\ADGroups.txt" $outputfile2 = "$env:userprofile\desktop\ADGroupMembers.txt" try { write-host Output File will be : $outputfile2 out-file -filepath $outputfile2 -inputobject "ADGroups" -encoding ascii } catch { write-host "Unable to write to the location: $outputfile2" } # write out the heading for the output file out-file -filepath $outputfile2 -inputobject "NAME,TYPE, EMAIL,MEMBERS,INACTIVE,MEMBERS" -encoding ascii # Set a progress counter so that the WRITE-PROGRESS bar can update in reference to the $ADGroups loop $ProgressCounter=0 # Get list of AD Groups $ADGroups = get-adgroup -filter * -properties *| where {$_.sid -notlike 'S-1-5-32*'} | sort name # Get list of AD users $ADUsers = get-aduser -filter * -Properties MemberOf | where {$_.sid -notlike '*-5??'} #| select name, samaccountname, enabled, sid, memberof | sort samaccountname write-host TOTAL GROUPS : $ADGroups.count write-host TOTAL USERS : $ADUsers.count # Work through the list of groups to identify members and count of members (and inactive members which are prefixed with *) foreach ($ADGroup in $ADGroups) { # Nice progress bar $progresscounter++ Write-Progress -Activity "Compiling Data" -status "Progress:" -currentoperation $GroupName -percentcomplete (($ProgressCounter / $ADGroups.count) * 100) $GroupName = $ADGroup.name $groupCat = $ADGroup.groupcategory $groupmail = $ADGroup.mail $membercount = 0 $inactivecount = 0 $membernames = @() # Run through each ($ADUSER.SAMACCOUNTNAME).MEMBEROF to match against $ADGROUP.name for matches foreach ($user in $ADusers) { $member = $user | where {$_.memberof -like "*$groupname*"} if ($member.length -lt 1) { # This user is not a match (resulting user count=0) } else { # We got a matching user who is a member of $ADGROUP.NAME $membercount++ if ($user.enabled -eq $true) { $membernames += $user.samaccountname # write-host " " $groupname ":"$user.samaccountname } else { # Tag the disabled accounts with a * symbol $inactivecount++ $membernames += "*" + $user.samaccountname # write-host " " $groupname ":*"$user.samaccountname } # end of if $user enabled } # end of if $member.length } # end of foreach $User # This group is finished processing # Sort the list of members into a string to make life simple when using the data... $memberstring = "" $membernames = $membernames | sort # Pipe the data into a pipe delimited string for output foreach ($member in $membernames) { $memberstring += "$member|" } # write-host "NAME,TYPE,EMAIL,MEMBERCOUNT,INACTIVECOUNT,MEMBERS" write-host "$GroupName,$groupCat,$groupmail,$Membercount,$inactivecount,$memberstring" out-file -filepath $outputfile2 -inputobject "$GroupName, $groupCat, $groupmail, $Membercount, $inactivecount, $memberstring" -append -encoding ascii } write-host "Complete!" While this code may not exactly be great, it produces exactly what I want in the way of output.
I import this file into Excel using text to columns, using comma as the delimiter, and save off for reference.
This has saved hours if not days over the last couple of weeks dipping in and out of housekeeping AD.
One thing I think I could do better is use an array to store the resulting data, but as I say, Im new to Powershell so revising this can go on a to-do list.
Just wanted to share the results.
Thanks
- Edited by Dustynet Thursday, December 22, 2016 8:11 AM
------------------------------------
Password expire script more than 6 months in AD
Hi Team,
Please somebody let me know the powershell script to pull whose password has been exipred more than 6 months in active directory. I need only the list of users whose password has been exipred morethan 6 months.
thanks.
Reply:
------------------------------------
Reply:
import-module activedirectory $TodayDate=get-date $reportObject = @() $userList = get-aduser -filter {Enabled -eq $True -and PasswordNeverExpires -eq $False } -Properties displayname, passwordexpired,"msDS-UserPasswordExpiryTimeComputed",logoncount,passwordlastset, badlogoncount,lastbadpasswordattempt,mail | select displayname, passwordexpired,"msDS-UserPasswordExpiryTimeComputed",logoncount,passwordlastset, badlogoncount,lastbadpasswordattempt,mail | sort-object msDS-UserPasswordExpiryTimeComputed -descending $obj = new-object PSobject foreach ($user in $userList) { $outputexp = ([datetime]::FromFileTime($user."msDS-UserPasswordExpiryTimeComputed")) $dateExpire= $outputexp $datestring=$TodayDate $dateshort= $TodayDate $expireShort=$dateExpire if ($dateExpire -lt ([datetime]::Today).AddDays(7)) { $obj = new-object PSobject $obj | add-member noteproperty Name($user.displayname) $obj | add-member noteproperty Expired($user.Passwordexpired) $obj | add-member noteproperty 'Expire date'($outputexp) $obj | add-member noteproperty 'Logon Count'($user.logoncount) $obj | add-member noteproperty 'Last Set'($user.PasswordLastSet) $obj | add-member noteproperty 'Bad Count'($user.badlogoncount) $obj | add-member noteproperty 'Bad Attempt'($user.lastbadpasswordattempt) $obj | add-member noteproperty 'Mail'($user.mail) $reportObject += $obj} } $reportObject Had this laying around it will show password expired less than 7 days change the if condition for -gt 150 days or whatever, additional info included in output.------------------------------------
Reply:
I would suggest using the Get-ADUser PowerShell cmdlet, and use the PasswordLastSet property. For example:
https://gallery.technet.microsoft.com/office/Get-ADUser-to-see-password-fcce5cc3
I think something similar to below will give you what you want:
# Retrieve domain maximum password age policy, in days. $MaxPasswordAge = (Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge.Days # Find the date that many days in the past. $Date1 = (Get-Date).AddDays(-$MaxPasswordAge) # Find the date 182 days further in the past. Any user with pwdLastSet older than this # has had an expired password for the past 6 months. $Date2 = ($Date1).AddDays(-182) # Find all enabled users with passwords that can expire and the password has been expired for at least 6 months. Get-ADUser -Filter {Enabled -eq $True -And PasswordNeverExpires -eq $False -And PasswordLastSet -lt $Date2} -Properties PasswordLastSet Richard Mueller - MVP Enterprise Mobility (Identity and Access)
- Edited by Richard MuellerMVP Wednesday, December 21, 2016 2:30 PM added code
------------------------------------
Reply:
Seems like, above scripts should help you to get the desired result of password expiration.
Alternatively, you can try using this password expiration reminder tool which helps to fetch such expired password reports in real time.
------------------------------------
Windows Update stuck on downloading on Server 2012
Hi,
Using VMWare Workstation 9, I created new virtual machine where I installed Windows Server 2012 Standard edition from MDSN disk en_windows_server_2012_x64_dvd_915478.iso In the Server 2012 virtual machine, when I go to check for updates it says there are important updates available so I click on Install Updates. It then just gets stuck on downloading updates for hours and nothing ever happens. Stuck at 0 KB total, 0% complete. I am able to access web pages using Internet Explorer with no problem so the machine does appear to have connectivity to the Internet. If I go to help, click on "What can I do if I'm having problems installing updates?" and click on "Tab or click to open the Windows Update troubleshooter" it says "Windows Online Troubleshooting Service is not enabled for this version of Windows." Any suggestions or ideas?
Thanks,
Greg
- Edited by Gregory Riggs Friday, July 12, 2013 9:57 PM
Reply:
------------------------------------
Reply:
------------------------------------
Reply:
------------------------------------

No comments:
Post a Comment