Tuesday, May 24, 2016
Calling Powershell script from Control-M
call PowerShell -NoLogo -NoProfile -NonInteractive -ExecutionPolicy "Bypass" -Command "& '\\path\to\pscript\myscript.ps1'" < NUL
Execute Powershell scripts at command line
Powershell’s default setting does not allow for execution of scripts
C:\>powershell # enter powershell
Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.
PS C:\> Get-ExecutionPolicy # check what the rights are
Restricted
PS C:\> Set-ExecutionPolicy RemoteSigned # reset the rights
PS C:\> Get-ExecutionPolicy # make sure the change took
C:\>powershell # enter powershell
Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.
PS C:\> Get-ExecutionPolicy # check what the rights are
Restricted
PS C:\> Set-ExecutionPolicy RemoteSigned # reset the rights
PS C:\> Get-ExecutionPolicy # make sure the change took
Now can execute scripts at command line
Enable Disk Cleanup on Windows Server 2008 / 2008 R2
In order to use cleanmgr.exe you’ll need to copy two files that are already present on the server, cleanmgr.exe and cleanmgr.exe.mui. Use the following table to locate the files for your operating system.
Windows Server 2008 R2 64-bit
C:\Windows\winsxs\amd64_microsoft-windows-cleanmgr_31bf3856ad364e35_6.1.7600.16385_none_c9392808773cd7da\cleanmgr.exe
Windows Server 2008 R2 64-bit
C:\Windows\winsxs\amd64_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_6.1.7600.16385_en-us_b9cb6194b257cc63\cleanmgr.exe.mui
Windows Server 2008 64-bit
C:\Windows\winsxs\amd64_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_6.0.6001.18000_en-us_b9f50b71510436f2\cleanmgr.exe.mui
Windows Server 2008 64-bit
C:\Windows\winsxs\amd64_microsoft-windows-cleanmgr_31bf3856ad364e35_6.0.6001.18000_none_c962d1e515e94269\cleanmgr.exe.mui
Windows Server 2008 32-bit
C:\Windows\winsxs\x86_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_6.0.6001.18000_en-us_5dd66fed98a6c5bc\cleanmgr.exe.mui
Windows Server 2008 32-bit
C:\Windows\winsxs\x86_microsoft-windows-cleanmgr_31bf3856ad364e35_6.0.6001.18000_none_6d4436615d8bd133\cleanmgr.exe
Once you’ve located the files move them to the following locations:
Cleanmgr.exe should go in %systemroot%\System32.
Cleanmgr.exe.mui should go in %systemroot%\System32\en-US.
You can now launch the Disk cleanup tool by running Cleanmgr.exe from the command prompt.
Disk Cleanup can now be run by entering Cleanmgr.exe into a command prompt, or by clicking Start and typing Cleanmgr into the Search bar.
https://technet.microsoft.com/en-us/library/ff630161(WS.10).aspx
Windows Server 2008 R2 64-bit
C:\Windows\winsxs\amd64_microsoft-windows-cleanmgr_31bf3856ad364e35_6.1.7600.16385_none_c9392808773cd7da\cleanmgr.exe
Windows Server 2008 R2 64-bit
C:\Windows\winsxs\amd64_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_6.1.7600.16385_en-us_b9cb6194b257cc63\cleanmgr.exe.mui
Windows Server 2008 64-bit
C:\Windows\winsxs\amd64_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_6.0.6001.18000_en-us_b9f50b71510436f2\cleanmgr.exe.mui
Windows Server 2008 64-bit
C:\Windows\winsxs\amd64_microsoft-windows-cleanmgr_31bf3856ad364e35_6.0.6001.18000_none_c962d1e515e94269\cleanmgr.exe.mui
Windows Server 2008 32-bit
C:\Windows\winsxs\x86_microsoft-windows-cleanmgr.resources_31bf3856ad364e35_6.0.6001.18000_en-us_5dd66fed98a6c5bc\cleanmgr.exe.mui
Windows Server 2008 32-bit
C:\Windows\winsxs\x86_microsoft-windows-cleanmgr_31bf3856ad364e35_6.0.6001.18000_none_6d4436615d8bd133\cleanmgr.exe
Once you’ve located the files move them to the following locations:
Cleanmgr.exe should go in %systemroot%\System32.
Cleanmgr.exe.mui should go in %systemroot%\System32\en-US.
You can now launch the Disk cleanup tool by running Cleanmgr.exe from the command prompt.
Disk Cleanup can now be run by entering Cleanmgr.exe into a command prompt, or by clicking Start and typing Cleanmgr into the Search bar.
https://technet.microsoft.com/en-us/library/ff630161(WS.10).aspx
Wednesday, May 18, 2016
Setting max file size to current physical size
Scenario: On SQL 2008R2 server, Tempdb has unlimited growth max size and is in danger of filling disk.
Need a quick way to set max size to current size to prevent further growth until can assess if there is an abnormal process taking up TempDB, what optimal size of TempDB should be, and/or disk space can be added.
SELECT 'ALTER DATABASE [' + db_name(A.database_id)
+ '] MODIFY FILE ( NAME = N''' + A.name
+ ''', MAXSIZE = '
+ cast((B.size_on_disk_bytes/1024) as varchar) + ' KB)'
, A.*
, B.*
FROM master.sys.master_files A
JOIN sys.dm_io_virtual_file_stats( db_id('tempdb'),NULL) B
ON A.file_id = B.file_id
WHERE A.database_id = db_id('tempdb')
Need a quick way to set max size to current size to prevent further growth until can assess if there is an abnormal process taking up TempDB, what optimal size of TempDB should be, and/or disk space can be added.
SELECT 'ALTER DATABASE [' + db_name(A.database_id)
+ '] MODIFY FILE ( NAME = N''' + A.name
+ ''', MAXSIZE = '
+ cast((B.size_on_disk_bytes/1024) as varchar) + ' KB)'
, A.*
, B.*
FROM master.sys.master_files A
JOIN sys.dm_io_virtual_file_stats( db_id('tempdb'),NULL) B
ON A.file_id = B.file_id
WHERE A.database_id = db_id('tempdb')
Tuesday, May 3, 2016
Subscribe to:
Posts (Atom)